Repository navigation
docs: add Express graceful shutdown guide with pinned behaviour tests - #661
Open
paulolubanwo391-cloud wants to merge 1 commit into
Open
paulolubanwo391-cloud wants to merge 1 commit into
paulolubanwo391-cloud wants to merge 1 commit into
Conversation
|
@paulolubanwo391-cloud Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
paulolubanwo391-cloud
force-pushed
the
docs/610-express-graceful-shutdown
branch
from
October 12, 2026 05:27
c772a6e to
05000dc
Compare
paulolubanwo391-cloud
force-pushed
the
docs/610-express-graceful-shutdown
branch
2 times, most recently
from
October 14, 2026 22:58
f9ada6f to
3e50e4f
Compare
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.
Summary
Adds
docs/graceful-shutdown.md: how an Express host should close its HTTP server and release Anchor-Kit resources in the correct order, with a working SIGINT/SIGTERM example.Closes #610.
Why
docs/plugin-lifecycle.mdstates the host ownsshutdown, but never showed how to combine it with closing the host's own HTTP server. Hosts were left to guess the ordering, and the two failure modes (a listener that outlives cleanup, and a forced exit that truncates a drain) are both easy to get wrong.The ordering matters:
anchor.shutdown()stops the watchers and the queue, so exiting first can lose work the queue already accepted.The guide
requestlistener that counts in-flight work, aserver.close()drain, thenawait anchor.shutdown(), then exit.anchor.shutdown()actually does" section covering the real semantics.process.exit(0)unconditionally, and why it exits non-zero on cleanup failure.Tests
tests/core/graceful-shutdown.test.ts— 8 cases that pin every behavioural claim in the guide, so the documentation cannot drift away from the implementation:getExpressRouter()is unavailable after shutdownI confirmed these bite: removing the in-flight
shutdownPromiseguard insrc/core/factory.tsfails the dedup test.Two corrections found by type-checking the example
I compiled the documented example against the real API rather than assuming it was right, and it did not type-check at first:
'request'listener on the Node server, which has nonextcallback — the original draft passed one and failed to compile. Express middleware is what suppliesnext, and the router is mounted above this listener.getExpressRouter()returnsExpressLikeMiddleware, so the example mounts it directly instead of casting toexpress.RequestHandler, matchingexample/express-app.ts.Verification
bun testbun run typecheck(tsc --noEmit && eslint . --max-warnings 0)prettier --checktsc(verified with a temporary harness, since an unused snippet in a.mdfile is not otherwise type-checked)No production code changed, so no runtime behavior is affected. No new dependencies.
Notes for review
configandawait anchor.init()in the way the existingexample/express-app.tsdoes; I kept the snippet focused on shutdown rather than restating full config setup.