Let hang detection see TS-streams deadlocks with in-isolate JS #8938
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 595 lines diff across 7 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.382
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8938"
general
weight: 0.35
jasnell
Under
typescript_implemented_streams, a Worker that deadlocks itself through a stream hangs forever. Under the C++ implementation, the same Worker fails with "...your Worker's code had hung and would never generate a response". One example: an HTMLRewriter element handler that awaits a write to the rewriter's own input, which the rewriter can't read until the handler returns.Cause
Hang detection fails a request that holds no pending events and has nothing else left to run. Waiting on something that only JavaScript in the same isolate can complete must therefore not hold a pending event. The C++ streams implementation reads and writes streams with
awaitIoLegacy()for this reason (see the TODOs ininternal.c++): the other end of a stream may be JavaScript, such as anIdentityTransformStream's writer or HTMLRewriter's handlers. Streams backed by external I/O hold their own pending events while that I/O is in flight (system-streams.c++).The TypeScript implementation's bridges to native streams waited with
awaitIo(), which holds a pending event, in three places:pumpQueuedTsStream()), which feeds HTMLRewriter's input;arrayBuffer(),text()and friends), which reads HTMLRewriter's output;ReadableStreamNativeSource's default and BYOB pulls, which read HTMLRewriter's output through a reader.Fix
Add
IoContext::awaitIoWithoutPendingEvent(), which isawaitIo()minus the pending event, and use it in those three places. That matches the C++ implementation's waits. I added a new name rather than reusingawaitIoLegacy(), which is deprecated because it lacks a continuation function. End/close and native pipes still hold pending events, as their C++ counterparts do.Test
htmlrewriter-deadlock-testsets up that deadlock and consumes the rewriter's output two ways, witharrayBuffer()and with a reader. It expects the request to fail with the hang error, under both implementations. Before this change both TypeScript cases hung until the test timed out. Reverting any one of the three sites hangs a case again.Checked on bazelflare:
htmlrewriter-test,http-test,http-standard-test,cache-test,streams/streams-test,streams/body-read-operation-test,streams-error-edge-cases-test,streams-terminal-state-test,pipe-source-error-uaf-test,js-readable-stream-testandjs-writable-stream-testpass in their default variants, and the wd-tests among them also pass in@all-compat-flags.Known remaining TypeScript-streams failures
I added
typescript_implemented_streamsto the configs of the tests above, plus the socket and node tls/net tests, and ran them on main and on this branch. Both runs fail the same cases, except forhtmlrewriter-test:| Test | Failing cases | First error |
| --- | --- | --- |
|
htmlrewriter-test|manualWriting2,streamingReplacement,streamingReplacementBadUTF8,streamingReplacementHTML| On main,manualWriting2hangs until the test times out, so the cases after it never run. With this PR all four fail at once with the hang error. They awaitTransformStreamwrites before reading, which depends onoriginal-transform-stream-backpressure. The test config sets that flag, but the TypeScript implementation doesn't support it. ||
http-test|http-test:test,http-test-cache-option-enabled:test,cacheMode| Value assertions ||
http-socket-test|socketFetcherUnusable| Deep-equal assertion ||
streams-terminal-state-test|bufferedClosePreservesLifecycle,bufferedErrorPreservesLifecycle,terminalSettlementPreservesLifecycle,cachedByobResponseDuringClose| Lifecycle records differ (e.g.nestedError);Cannot read properties of null (reading 'view')||
streams/body-read-operation-test|bodyReadUsesOperationLocalBytes,callbacksRetainPendingBodyRead,pendingBodyReadRequiresCompletion,uploadAbortDuringReasonConversion| "Expected a rejection"; hang error; "adoption failed"; "upload failed" ||
node/tests:tls-nodejs-test| 6 cases | "The strategy for a byte stream cannot have a size function" |Pass with the flag on:
cache-test,http-standard-test,streams/streams-test,streams-error-edge-cases-test,pipe-source-error-uaf-test,connect-handler-test,connect-handler-starttls-lifetime-test,js-rpc-socket-test,socket-close-gc-test,socket-proxy-to-test,sockets-connect-error-test,outbound-interceptor-socket-test,starttls-nodejs-test,net-nodejs-test.The companion fix for sockets upgraded with
startTls()is in #8937.🤖 Generated with Claude Code