Skip to content

fix: cancel in-flight backplane I/O on Shutdown#111

Merged
joaomdsg merged 1 commit into
mainfrom
fix/backplane-context-shutdown
Jun 10, 2026
Merged

fix: cancel in-flight backplane I/O on Shutdown#111
joaomdsg merged 1 commit into
mainfrom
fix/backplane-context-shutdown

Conversation

@joaomdsg

Copy link
Copy Markdown
Member

Problem (critic panel blocker #1)

Every backplane call site passed context.Background()Subscribe, Append, CAS, LoadSnapshot, Compact, and the keystore Key/KeyFor. A wedged backend could keep an in-flight call alive forever, so App.Shutdown could never drain.

Fix

  • App-scoped backplaneCtx/backplaneCancel, created in New, cancelled in Shutdown.
  • Cancel ordering: after action drain (srv.Shutdown) and OnDispose (so graceful writes still complete on a live ctx), before backplane.Close().
  • Threaded backplaneCtx through every backplane I/O call site (incl. StateApp.Update's RMW CAS path).

Tests

  • TestShutdownCancelsInflightBackplaneContext — projector's Subscribe + LoadSnapshot contexts are live while running, context.Canceled after Shutdown.
  • TestShutdownCancelsBackplaneWritePathContext — drives StateApp.Update and asserts the CAS context is cancelled by Shutdown.

Full ci-check.sh green (gofmt, vet, golangci, govulncheck, -race, alloc gates).

Every backplane call (Subscribe/Append/CAS/LoadSnapshot/Compact and the
keystore Key/KeyFor) rode context.Background(), so a wedged backend could
keep an in-flight call alive forever and block App.Shutdown's drain.

Add an app-scoped backplaneCtx/backplaneCancel created in New and cancelled
in Shutdown (after the action drain and OnDispose, before backplane.Close so
graceful writes still complete). Thread it through all backplane call sites.

Closes the panel's #1 production blocker.
@joaomdsg
joaomdsg merged commit 5a0b560 into main Jun 10, 2026
4 checks passed
@joaomdsg
joaomdsg deleted the fix/backplane-context-shutdown branch June 10, 2026 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant