chore(docker): keep memcached alive and fail open on cache delete - #771
Open
adekbadek wants to merge 2 commits into
Open
chore(docker): keep memcached alive and fail open on cache delete#771adekbadek wants to merge 2 commits into
adekbadek wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TB2Ju1sF5WXb97sV32HMsu
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TB2Ju1sF5WXb97sV32HMsu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
All Submissions:
Changes proposed in this Pull Request:
Local dev only — the drop-in is copied into the container by
run.shand never ships to publishers.In an isolated env,
update_post_meta()followed byget_post_meta()in the same request returned the stale value while the DB held the new one.wp_cache_delete()andclean_post_cache()did not help. Two of fifteen running env containers were affected.memcached had died, and nothing supervises it. With the backend unreachable, the drop-in treats its in-process array asymmetrically:
set()$this->cache[$key]unconditionallyget()$this->cache[$key]delete()unset()only iffalse !== $result— so neverMemcache::delete()returnsfalsewhen the server is unreachable, so the runtime entry survives and the cache degrades into one that can never be invalidated. Core invalidates post meta via delete, soupdate_post_meta()became a no-op against the cache. Anything writing and reading back in one request — CLI migrations, tests — got false results with no outward signal.Changes:
delete()andreplace()always drop the runtime entry. The one that matters: it turns a silent correctness bug into, at worst, a slower local site.connection_errors(written, never read, previously one entry per failed op).bin/watchdog-memcached.sh— a 30s TCP probe that restarts memcached. Bind-mounted via/var/scriptsrather than inline inrun.sh, so later changes to it need no image rebuild. Noset -e, so a failed restart can't end the loop.n env upso the ~43 existing env files get one. Tuned to flag only a memcached the watchdog could not revive, withstart_periodcovering a cold boot.run.shis baked into the image, so the watchdog needs one./build-image.shto start; the drop-in applies on container restart.How to test the changes in this Pull Request:
main, kill memcached in any env container:update_post_meta(), thenget_post_meta()it back in onewp eval-file. Returns''while a direct SELECT returns the value.bin/object-cache.phpin the container'swp-content/, memcached still down:wp-content/debug.logreports the outage once per process:Memcached object cache: cannot reach 127.0.0.1:11211…MEMCACHED_WATCHDOG_INTERVAL=2 /var/scripts/watchdog-memcached.sh, then kill memcached three times withpkill -x memcached. It recovers each time and the loop survives.docker exec <container> bash -c 'echo > /dev/tcp/127.0.0.1/11211'exits non-zero with memcached down, zero with it up.n env up <name>on an env created before this branch inserts the healthcheck; re-running inserts nothing.Other information:
All six steps verified on a live container; both compose files and a migrated env file parse via
docker compose config.