stream,http,http2: use public stream state accessors #67677
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.46) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.46 · 475 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 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.369
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #67677"
general
weight: 0.35
Ethan-Arrowood
Motivation
lib/internal/http/,lib/internal/fs/,lib/zlib.js,lib/internal/console/and
lib/internal/webstreams/reach into_readableState/_writableStatedirectly. That couples non-streams modules to the internal state objects'
shape, so refactoring
lib/internal/streams/(e.g. replacing boolean flagswith bitmask fields) silently ripples outward.
This PR exposes the needed state through the same public accessor surface
already used for
readableLength,writableLength, etc., and migrates everycall site that has a public equivalent. Depending on the internal state object
outside
lib/internal/streams/is reduced from 43 references to 17, andthe remaining ones are genuinely internal writes / state hand-offs with no
sensible public accessor.
New public accessors
Readable / Writable (and Duplex where applicable):
readableErrored/writableErrored— exposes the per-sideerroredstate. On a
Duplex,stream.erroredreflects only the readable side, sothe writable-side getter is wired into
Duplextoo. (Note: theObject.keys(Writable.prototype)copy loop that buildsDuplex.prototypeskips non-enumerable getters, so these are added explicitly.)
readableHighWaterMark/writableHighWaterMark— now settable, validatedthrough a shared
validateHighWaterMarkhelper that throwsERR_INVALID_ARG_VALUEon non-integer / negative values.writableDefaultEncoding— getter.readableErrorEmitted/writableErrorEmitted— getters.readableResumeScheduled— getter.isPaused()is not equivalent:calling
resume()while a'readable'listener is attached leavesisPaused()true whileresumeScheduledis set, so the flag is exposedverbatim to preserve behaviour.
autoDestroy— getter/setter on Readable and Writable. TheDuplexaccessor keeps
_readableState.autoDestroyand_writableState.autoDestroyin sync when set dynamically, matching how
destroyedis already handled.Call sites migrated
lib/internal/http2/core.jslib/internal/http/outgoing.js,incoming.js,agent.js,server.jslib/internal/fs/streams.jslib/zlib.jslib/internal/console/constructor.jslib/internal/http2/compat.jslib/internal/webstreams/adapters.js(duck-typing checks switched toinstanceof Readable/instanceof Duplex)http2
receivedEndlib/internal/http2/core.jsonStreamClose()now readsHttp2Stream[kState].receivedEndinstead of_readableState.ended. The flagis set by an override of
Http2Stream.prototype.pushon anynullpush of thereadable side, so it mirrors
_readableState.endedexactly and coversserver-initiated push streams whose readable side ends on a clean close (not a
peer
END_STREAM).This reconciles cleanly with the existing
STREAM_FLAGS_CLEAN_REQUEST_RESEThandling:
receivedEnddrives the "peer did not END_STREAM → abort therequest" decision, while the clean-reset flag governs keeping a client
response readable.
Http2Stream._destroy()reads the samereceivedEndflaginstead of
_readableState.endedwhen recording an incomplete request.Fix a regression
Making the high-water-mark setter validating caused
new IncomingMessage(<truthy non-socket>)to throwERR_INVALID_ARG_VALUEwith an
undefinedhighWaterMark.lib/internal/http/incoming.jsnow onlysyncs the socket high-water mark when it is defined.
Tests
New tests:
test/parallel/test-stream-errored-accessors.jstest/parallel/test-stream-settable-highwatermark.jstest/parallel/test-stream-state-accessors.jsAnd an extended
test-stream-duplex-/test-stream-coverage for theautoDestroysetter. Ran the fulltest/parallelstream, http2 (300, incl.compat), http, fs, zlib and console suites.