Skip to content

fix(reset): release what a plugin started, not only what it minted (#902, #903) - #1036

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/902-903-reset-plugin-started-state
Sep 17, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/902-903-reset-plugin-started-state

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #902
Closes #903

#886 gave the plugin registry a ResetForRun hook 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 the StateManager only 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 of Shutdown could 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, and ReplayEngine.resetState.

S3's object payloads (#902)

The bytes live in an afero filesystem 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. ResetForRun now empties the filesystem.

Two implementation choices, both measured rather than predicted:

  • Emptied in place, not replaced. Handlers read p.fs without a lock and ResetForRun is documented as safe to call while requests are in flight, so assigning a fresh MemMapFs would race with a request already in one.
  • Each root entry removed, not 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; with RemoveAll("/") 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)

DeleteEventSourceMapping is the only call that closes a poller's stop channel, and it answers ResourceNotFoundException once 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.DrainPool rather than StopAll — StopAll closes the channel the eviction goroutine selects on, so calling it here would leave every container started after a reset warm until Shutdown, however long it sat idle. StopAll is now layered on DrainPool, and Shutdown stops 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 the substrate-rds-<id> Docker name the next CreateDBInstance needs — which fails docker run and falls back silently to a synthetic endpoint. Two adjacent defects in the same file went with it: StopContainer did not docker rm the container although its doc comment claimed it did, and nothing ever dropped the active entry, so the map grew for the life of the process and StopAll re-stopped containers it had already stopped.

Tests

In emulator/replay_plugin_reset_test.go, beside #886's:

  • S3: two versioned PutObjects over the wire, the exact payload path set asserted, a reset, the set asserted empty, then a further write and a GetObject that reads its bytes back. Stubbing the emptying out fails it with the three surviving paths named; RemoveAll("/") fails it on the walk.
  • The injected filesystem survives a reset, read back through the test's own afero reference.
  • The pollers: create an SQS mapping, assert one poller, reset, assert none — and assert DeleteEventSourceMapping on 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.
  • DrainPool vs StopAll: eviction still running after the first, stopped after the second.
  • RDS: the two configurations reachable without Docker; the executor's bookkeeping is asserted in rds_exec_test.go beside the existing Docker-gated tests.

Both invisible-through-the-wire assertions go through export_test.go accessors 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.md now 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 test on 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.

, #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

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.53846% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/s3_plugin.go 76.47% 4 Missing ⚠️
emulator/lambda_plugin.go 91.66% 1 Missing ⚠️
emulator/rds_exec.go 93.33% 1 Missing ⚠️
emulator/rds_plugin.go 83.33% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit d93b7c5 into main Sep 17, 2026
16 of 17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/902-903-reset-plugin-started-state branch September 17, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant