Repository navigation
Stop gotoReady() spinning on closed or settled states - #1849
Merged
ajeetdsouza merged 2 commits intoOct 27, 2026
Merged
ajeetdsouza merged 2 commits into
ajeetdsouza merged 2 commits into
Conversation
1 task done
princejain756
force-pushed
the
fix-session-manager-gotoready-spin
branch
from
October 22, 2026 20:27
5ec6c2a to
eae77fa
Compare
The while loop in gotoReady() only handled "error" and "connecting". A "closed" state had no wait condition, so the loop spun forever - and a "connecting" state whose promise had already resolved spun at 100% CPU whenever ready() threw inside the state transition, e.g. when the session died between connecting and becoming ready. The loop now reconnects from "closed", matching the entry branch, and the "connecting" promise handler catches a throwing ready() so the manager lands in "error" and pending callers reject instead of spinning. Fixes connectrpc#1841 Signed-off-by: Prince Jain <[email protected]>
princejain756
force-pushed
the
fix-session-manager-gotoready-spin
branch
from
October 23, 2026 02:23
eae77fa to
3f4f58b
Compare
Signed-off-by: Ajeet D'Souza <[email protected]>
ajeetdsouza
approved these changes
Oct 27, 2026
Contributor
|
Thanks, this looks great! :) |
princejain756
added a commit
to princejain756/princejain756
that referenced
this pull request
Oct 27, 2026
This was referenced Oct 27, 2026
Merged
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
Http2SessionManager.gotoReady()can spin forever. Its wait loop only handled the"error"and"connecting"states:Two states can reach that loop without a wait condition:
"closed"- reachable whilegotoReady()is awaiting verification: a graceful close (idle timeout, GOAWAY, server close) transitions the manager to"closed"underneath theawait, and the loop then has nothing to wait for and no branch to take."connecting"with an already-resolved promise - this is the 100% CPU freeze reported in Http2SessionManager.gotoReady spins at 100% CPU when the state is closed or stuck in connecting #1841. If the http2 session dies between connecting and becoming ready,ready()throwsConnectError: [internal] expected open sessioninside thestate.conn.then(...)handler insetState(). The exception is swallowed by the promise machinery, the manager stays"connecting"with a settledconn, andawait this.s.connreturns instantly on every iteration - a pinned core with the only stack frame insidegotoReady().Changes
"closed", matching the method's entry branch."connecting"promise handler wrapssetState(ready(...))in try/catch and falls back tosetState(closedOrError(e)), so a dead session lands the manager in"error"and pendingconnect()/request()callers reject instead of spinning.Test plan
Two regression tests in
http2-session-manager.spec.ts:should open a new connection if the existing one closes after a successful verification PING- destroys the server session in apinglistener so the PING acknowledgement and teardown travel in the same turn; verification resolves while the manager transitions to"closed". Without the fix the request never settles.should reject if the connection dies before it becomes ready- injects a"connecting"state whose promise resolves to an already-closed session, deterministically reproducing theready()throw. Without the fix the whole spec file hangs (verified:timeoutkills the suite at the reported freeze); with the fix the request rejects with aConnectError.All 114 tests in
packages/connect-nodepass,tsc --noEmitandbiome lint/formatare clean.Fixes #1841