Repository navigation
Description
Found while auditing plugin-held mutable state for #886.
#886 added ResettablePlugin so a reset can return plugin-held mutable state to its start-of-run value, and implemented it for the three plugins whose state feeds a minted identifier (S3Plugin.versionSeq, SESv2Plugin.msgSeq, OmicsPlugin.rng). The audit turned up three more pieces of plugin-held mutable state, all of them process-lifecycle rather than identifier-minting, and all of them deliberately out of #886's scope:
| plugin | field | what it holds |
|---|---|---|
LambdaPlugin |
esmStop map[string]chan struct{} (emulator/lambda_plugin.go:32) |
one stop channel per event-source mapping, each with a live go p.sqsPollerLoop(...) goroutine (:1241, :1374) |
LambdaPlugin |
executor *LambdaExecutor (emulator/lambda_plugin.go:29) |
pool map[string]*containerHandle of warm containers (emulator/lambda_exec.go:39-47) |
RDSPlugin |
executor *RDSExecutor (emulator/rds_plugin.go:22) |
active map[string]*RDSContainerHandle of live Postgres containers (emulator/rds_exec.go:25-29) |
All three are torn down in the plugin's Shutdown, and by nothing else. So after POST /v1/state/reset — or a replay reset — the event-source-mapping records are gone from the StateManager while their poller goroutines keep running against queues that no longer exist, and the container pools keep whatever they had.
Why this was not folded into #886
Stopping a poller or tearing down a container is not reversible the way rewinding a counter is, and per the scope boundary in CLAUDE.md the executors run the workload rather than answer an API observation — so "reset" for them is a lifecycle question (what should a mid-run reset do to work already in flight?) rather than a determinism one. It wants its own decision.
What needs deciding
- Should a state reset stop the ESM pollers whose records it just deleted? A poller that outlives its record is a goroutine leak with no API-visible owner.
- Should a state reset drain the Lambda warm-container pool and the RDS container set, or is a warm pool legitimately process-scoped (a cache, not state)?
- If yes to either, does that go through
ResetForRun(makingLambdaPluginandRDSPluginimplementers) or through a separate, coarser hook?
Acceptance criteria
- A decision recorded here for each of the three, with the reasoning.
- The chosen behaviour implemented.
- A test that creates an event-source mapping, resets state, and asserts no poller is still running (a goroutine count, or an assertion that the queue receives no further polls).
Activity
scttfrdmn commentedon Sep 17, 2026
Decision, one per row: stop the pollers, drain both container sets, and do it through
ResetForRun1. ESM pollers — stopped
A poller that outlives its record is not merely a leak; it acts on the next run.
DeleteEventSourceMappingis the only call that closes a stop channel, and it answersResourceNotFoundExceptiononce the record is gone — so after a reset the goroutine is unreachable through the API while still ticking every wall-clock second. Both the queue URL and the function ARN are name-derived, so the next test case to create a queue and a function under the same names has its messages received and deleted, and its function invoked, by a poller it never created. That is exactly the timing-dependent cross-case interferenceTestServer.ResetStateexists to remove, so this one is not a judgement call.One theory I had here was wrong and is worth recording so nobody re-derives it: a ghost poller does not pollute the recorded event stream.
PluginRegistry.RouteRequestcallsp.HandleRequestdirectly, with no pipeline and no event recording, so the poller's SQS traffic is invisible to the event store. The cross-case argument above is the real one, and it is stronger.2. Lambda warm pool — drained, through a new
DrainPoolrather thanStopAllA warm pool is a cache, so the issue's "legitimately process-scoped?" reading is defensible in general — but not as substrate keys it.
e.pool[fn.FunctionArn]is keyed by function ARN alone, with no revision or code identity in the key, so a function recreated under the same name after a reset would run the previous run's code. Dropping a warm container is always safe (the next invoke starts one), so there is no cost on the other side of the trade.It must not go through
StopAll, which is the trap in this row:StopAllcloses the channelevictLoopselects on, so a reset calling it would leave every container started afterwards warm untilShutdown, however long it sat idle. Hence a newLambdaExecutor.DrainPoolthat empties the pool and leaves the eviction goroutine running;StopAllis now layered on it.LambdaPlugin.Shutdownalso stops the pollers now — it did not before.3. RDS containers — stopped and removed
Same reachability argument as the pollers, plus a second failure:
DeleteDBInstancestops a container by reading"dbinstance_container:<scope>/<id>"back out of theStateManager, so once a reset deletes that key nothing short ofShutdowncan reach the container — and it still holds the Docker namesubstrate-rds-<id>that the nextCreateDBInstancefor the same identifier needs, which failsdocker runand falls back silently to a synthetic endpoint. So the leak degrades the next run rather than just consuming a container.Two adjacent defects found in the same file and fixed with it:
StopContainerdid notdocker rmthe container although its doc comment claimed it did (leaving the name taken), and nothing ever dropped theactiveentry — so the map grew for the life of the process andStopAllre-stopped containers it had already stopped.4. The hook —
ResetForRun, not a coarser oneThe existing contract ("return plugin-held mutable state to the value it had at the start of the run") fits all three without amendment, and all three reset paths —
POST /v1/state/reset,TestServer.ResetState,ReplayEngine.resetState— inherit it with no new wiring. A second, coarser hook would need three new call sites and a rule for which hook a new plugin implements.LambdaPluginandRDSPluginbecome implementers; the asserted set inTestPluginReset_DefaultPluginsImplementingTheHookgoes from three to five.On the scope-boundary worry in the issue: this does not model workload internals. It stops substrate's own goroutine and releases substrate's own container. Nothing here decides what the workload was doing.
On the third acceptance criterion — the form of the assertion
Deviating from both suggested forms, deliberately. Not an assertion that the queue receives no further polls: a poll happens only on a one-second wall-clock tick, so that test would depend on real elapsed time, which the house rules forbid. Not a goroutine count either:
runtime.NumGoroutine()counts everything the test binary is running in parallel. The assertion is the live-poller count —ESMPollerCountForTest, the number of stop channels the plugin holds — which is deterministic and exact, sincesqsPollerLoopreturns on that channel unconditionally. The test also asserts thatDeleteEventSourceMappingon the same UUID now answers 404, which is the record that no API call could have stopped the poller after a reset.The RDS container path needs Docker to have something to stop, so the plugin-level test covers the two configurations reachable without it (no executor, and an executor holding nothing) and the executor-level bookkeeping — that a stop drops the
activeentry — is asserted inrds_exec_test.gobeside the existing Docker-gated tests.Fix in the PR below, together with #902.
scttfrdmn commentedon Sep 17, 2026
One adjacent defect surfaced while auditing the warm pool for row 2 and is not fixed here, because it is a live-path bug with a different fix: nothing invalidates a warm container when the function's code changes either — not
UpdateFunctionCode, notDeleteFunction, onlyShutdownand the idle TTL — so with Docker execution enabled an update-then-invoke runs the previous code for up toWarmPoolTTL. Filed as #1035.DrainPoolis the wrong granularity for it (it drops every function's container), so it needs a per-ARN eviction at the point the code changes.