Close the connection when an upgraded socket closes, on TS streams #8937
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 315 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.344
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8937"
general
weight: 0.35
jasnell
Under
typescript_implemented_streams, closing the socket thatstartTls()returned leaves the connection open. The peer never sees it end, so a peer that waits for EOF hangs.Cause
startTls()andtakeConnectionStream()neutralize the old socket's readable by detaching it, and drop the detached copy. Under the C++ streams implementation, dropping the copy frees it at once, and with it its source's reference to the connection. Under TypeScript streams the copy is a JavaScript object, and its native source holds the connection until that object is garbage-collected. The writable side already handles this:WritableStreamNativeSink::detach()releases its sink eagerly.Fix
Socket::detachStreams()now cancels the detached readable instead of dropping it, which releases its source right away under both implementations. The cancellation reaches only the old socket's own reads (EncodedAsyncInputStream::cancel()cancels the reads it has pending), not the connection, which the new socket now owns.Test
connect-handler-starttls-close-testopens astarttlstunnel to a Durable Object'sconnect()handler. Both ends upgrade, the test closes its upgraded socket, and the handler reports through RPC how its pending read ended. The test runs the same worker under both implementations. Both now report the same disconnect error. Before this change the TypeScript run hung until the test timed out.Checked on bazelflare:
@,@all-autogates,@all-compat-flags).@and@all-compat-flags:connect-handler-test,connect-handler-starttls-lifetime-test,http-socket-test,socket-close-gc-test,socket-proxy-to-test,sockets-connect-error-test,outbound-interceptor-socket-test,js-rpc-socket-test,starttls-nodejs-test,tls-nodejs-test,net-nodejs-test, andsockets-test.typescript_implemented_streamsadded to their configs, the same tests fail exactly as they do on main:http-socket-test:socketFetcherUnusableand sixtls-nodejs-testcases ("The strategy for a byte stream cannot have a size function"). Those are separate TypeScript-streams gaps, listed in #8938.Not covered
When a
connect()handler closes its upgraded socket, the caller still sees no EOF until the handler returns. This happens under both implementations, so it's a different issue and this PR leaves it alone.🤖 Generated with Claude Code