Repository navigation
fix(reset): release what a plugin started, not only what it minted (#902, #903) - #1036
Merged
Merged
Conversation
, #903) A state reset returned plugin-held counters and random sources to their start-of-run values (#886) and left everything a plugin had *started* running: S3's object payloads, Lambda's event-source-mapping pollers and warm containers, RDS's Postgres containers. In each case the reset deleted the record that was the only way to reach the thing, so afterwards nothing short of Shutdown could stop it. S3Plugin.ResetForRun empties its payload filesystem, and only one it created — an injected Options["filesystem"] is the caller's, who holds the only reference that knows what is safe to remove. It empties in place rather than replacing the field, because handlers read p.fs without a lock, and it removes each root entry rather than calling RemoveAll("/"), which on a MemMapFs reports success, leaves every file beneath readable and destroys the root entry. LambdaPlugin.ResetForRun stops every poller and drains the warm pool through a new LambdaExecutor.DrainPool. Not StopAll: that closes the channel the eviction loop selects on, so every container started after a reset would stay warm until Shutdown. Shutdown now stops the pollers too. RDSPlugin.ResetForRun stops the executor's containers. RDSExecutor. StopContainer now also docker-rm's the container, as its doc comment already claimed, and drops the active entry — nothing did, so the map grew for the life of the process. Closes #902 Closes #903
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Closes #902
Closes #903
#886 gave the plugin registry a
ResetForRunhook and three plugins used it for a counter or a random source. The hook was owed a second class of state — what a plugin started rather than minted: a goroutine, a container, a buffer of bytes theStateManageronly holds metadata for. In each of the four cases below the reset deleted the record that was the only way to reach the thing, so after it nothing short ofShutdowncould stop what was left running. Both issues carry the decision record with the reasoning; this is the summary.All three reset paths inherit the fix with no new wiring:
POST /v1/state/reset,TestServer.ResetState, andReplayEngine.resetState.S3's object payloads (#902)
The bytes live in an
aferofilesystem on the plugin, and every read of them is gated on object metadata a reset deletes — so they were simultaneously unreachable and never freed, growing for the life of the process.ResetForRunnow empties the filesystem.Two implementation choices, both measured rather than predicted:
p.fswithout a lock andResetForRunis documented as safe to call while requests are in flight, so assigning a freshMemMapFswould race with a request already in one.RemoveAll("/"). That call reports success, leaves every file beneath the root readable, and destroys the root entry so nothing can be enumerated afterwards — a silent no-op on the payloads that also breaks the filesystem. The test asserts the filesystem is still usable for exactly this reason; withRemoveAll("/")in place it fails on the walk.The one exception is a filesystem the caller injected: it may be backed by a directory holding fixtures the caller means to keep, and only the caller knows that. Nothing can inject one over HTTP, so every server-hosted plugin — including the
TestServer#902 is about — is covered.Lambda's ESM pollers and warm containers (#903)
DeleteEventSourceMappingis the only call that closes a poller's stop channel, and it answersResourceNotFoundExceptiononce the record is gone — so a reset left a goroutine ticking every wall-clock second with no way to stop it. Queue URL and function ARN are both name-derived, so the next case to use the same names had its messages received and deleted, and its function invoked, by a poller it never created.The warm pool is keyed by function ARN alone, so a function recreated under the same name would run the previous run's code. It is drained through a new
LambdaExecutor.DrainPoolrather thanStopAll—StopAllcloses the channel the eviction goroutine selects on, so calling it here would leave every container started after a reset warm untilShutdown, however long it sat idle.StopAllis now layered onDrainPool, andShutdownstops the pollers too, which it did not before.RDS's Postgres containers (#903)
The container handle is read back out of the
StateManager, so a reset made the container unstoppable through the API while it still held thesubstrate-rds-<id>Docker name the nextCreateDBInstanceneeds — which failsdocker runand falls back silently to a synthetic endpoint. Two adjacent defects in the same file went with it:StopContainerdid notdocker rmthe container although its doc comment claimed it did, and nothing ever dropped theactiveentry, so the map grew for the life of the process andStopAllre-stopped containers it had already stopped.Tests
In
emulator/replay_plugin_reset_test.go, beside #886's:PutObjects over the wire, the exact payload path set asserted, a reset, the set asserted empty, then a further write and aGetObjectthat reads its bytes back. Stubbing the emptying out fails it with the three surviving paths named;RemoveAll("/")fails it on the walk.aferoreference.DeleteEventSourceMappingon that UUID now answers 404, which records that no API call could have stopped it. Stubbing the fix out fails it with a count of 1.DrainPoolvsStopAll: eviction still running after the first, stopped after the second.rds_exec_test.gobeside the existing Docker-gated tests.Both invisible-through-the-wire assertions go through
export_test.goaccessors whose doc comments say why no request can see them, and the poller assertion is a count rather than an absence of polls, because a poll happens on a wall-clock tick.docs/contributing.mdnow states the reachability test a new plugin should apply, the three cases, and the injected-state exception.One adjacent defect was found and deliberately not fixed here — nothing invalidates a warm container when the function's code changes either, so an update-then-invoke runs the previous code — filed as #1035, since it needs a per-ARN eviction on the live path rather than a drain.
Verification
Nine-command gate green:
gofmt/build/vet,golangci-lint,make test,make teston go1.26.6,make coverage, docs reference and version checks, the docs site build, and the e2e suite. Coverage holds the baseline at 85.1% emulator / 84.6% total.