Repository navigation
Add graceful server drain and opt-in resend for refused RPCs - #426
Merged
Merged
Conversation
Assisted-by: Replit
Long-lived procedures must not delay transport shutdown. Track admitted calls before middleware and finish when RPCs and uploads end, with a bounded timer as the deadline. Assisted-by: Replit
Only refused RPCs can be sent again on a fresh connected session. Keep waiting and cleanup in one named operation, and check cancellation before dispatching each resend. Assisted-by: Replit
Keep one behavior test for each drain and resend risk. Share the transport fixture and state when cancellation preserves a refusal instead of cancelling an in-flight call. Assisted-by: Replit
Armster15
force-pushed
the
server-drain-resend-refused
branch
from
October 21, 2026 22:49
161fcc0 to
6079d4a
Compare
Armster15
commented
Oct 21, 2026
Armster15
commented
Oct 21, 2026
Armster15
commented
Oct 21, 2026
Share the timer limit already used by the transport and let negative resend counts disable resend. Keep abort handling in the session waiter, remove unused fixture output, and shorten the README to the public contract. Assisted-by: Replit
Armster15
marked this pull request as ready for review
October 21, 2026 23:01
Armster15
requested review from
daweifeng-replit and
komalagrawal-alt
and removed request for
a team and
komalagrawal-alt
October 21, 2026 23:01
2 tasks
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.
Why
A shutting-down server must distinguish refused calls from calls that started. A refusal before middleware and handlers run is safe to resend.
What changed
server.drain({ budgetMs })to the TypeBox router. New procedures receiveSERVER_DRAININGbefore middleware or handlers run.maxResendsand per-waitnewSessionWaitMs. Each resend needs a connected session with a new ID.MAX_TIMER_DELAY_MSacross all three timer checks, accept negative resend counts as zero, and add focused behavior coverage and minimal documentation.This builds on the pending-handshake close fix, which is on main. This PR does not modify the handshake path.
Versioning
No wire envelope change.
ReaderErrorSchemagainsSERVER_DRAINING, so exhaustive built-in error switches need a new case. No version bump in this PR:package.jsonis not in the diff against main.Tests
npm run checkpasses TypeScript, Prettier, and ESLint.drain.test.ts:143getsOk(null).drain.test.ts:158finds the transport closed before its admitted RPC finishes.drain.test.ts:180finds the transport still open after both RPC and upload finish.drain.test.ts:192finds the transport open at the deadline.drain.test.ts:204sees three old-session requests instead of one.drain.test.ts:227sees four requests instead of three formaxResends: 2.Invalid resendRefusedCalls limitsbefore the first-refusal assertion atdrain.test.ts:237.drain.test.ts:250remains pending until the test times out.drain.test.ts:264remains pending until the test times out. With the listener restored, the later-connection checks at lines 270-271 show no resend.drain.test.ts:279remains pending until the test times out.All mutations were restored. The negative-budget and waiting-abort proofs were rerun in this fix pass. The other proofs remain valid with updated assertion-line references.
Appendix
Decisions
server.close()separately to dispose resources. Handlers must not emit the reserved refusal code. The experimental protobuf router is excluded.MAX_TIMER_DELAY_MS. Larger Node timer delays run after 1 ms.maxResendsmust be a safe integer. Non-positive counts disable resend.Facts verified in code
router/server.ts:242-256,569-571,805-807: admission, cleanup, and registration before middleware.router/server.ts:1081-1113: RPC/upload-only idle detection, bounded deadline, and promise resolution after transport close.router/client.ts:267-276,281-348,380-382: bounded configuration, fresh connected-session waiting, explicit listener cleanup, and RPC-only dispatch.router/client.ts:412-429,710-723: the RPC overload and the existing return relation.transport/transport.ts:40,139: shared timer limit, also imported by the router server and client.router/streams.ts:236andtransport/sessionStateMachine/common.ts:386: existing resolver-helper precedents.Review dispositions
~ written by ⠕ Replit