Repository navigation
Conversation
Collaborator
|
Review requested:
|
Member
Author
|
Validated locally against current main (rebased on ce44266): rebuilt out/Release and ran the affected suites. Test results (all green):
Also: eslint ( |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #67677 +/- ##
========================================
Coverage 90.60% 90.60%
========================================
Files 801 801
Lines 281056 281226 +170
Branches 54253 54296 +43
========================================
+ Hits 254660 254818 +158
+ Misses 16577 16576 -1
- Partials 9819 9832 +13
🚀 New features to boost your workflow:
|
Replace direct _readableState/_writableState access outside lib/internal/streams/ with the public accessors so internal modules no longer depend on the state objects' shape. Added accessors: - readableErrored / writableErrored (per-side; on a Duplex stream.errored only reflects the readable side, and writable-side getters must be wired into Duplex because the non-enumerable property copy loop skips them) - settable readableHighWaterMark / writableHighWaterMark (validated via a shared validateHighWaterMark helper, ERR_INVALID_ARG_VALUE) - writableDefaultEncoding, readableErrorEmitted / writableErrorEmitted - readableResumeScheduled (isPaused() is not equivalent: resume() with a 'readable' listener leaves isPaused() true while resumeScheduled is set) - autoDestroy get/set on Readable and Writable; a Duplex accessor keeps _readableState/_writableState.autoDestroy in sync when set dynamically Call sites migrated to the accessors: - lib/internal/http2/core.js, lib/internal/http/outgoing.js, lib/internal/http/incoming.js, lib/internal/http/agent.js, lib/internal/http/server.js, lib/internal/http2/compat.js, lib/zlib.js, lib/internal/console/constructor.js, lib/internal/fs/streams.js - lib/internal/webstreams/adapters.js drops duck-typing checks for instanceof Readable / Duplex http2 receivedEnd: Http2Stream tracks when its readable side reached EOF via a receivedEnd flag set on any null push (an exact mirror of _readableState.ended). onStreamClose() and _destroy() read stream[kState].receivedEnd instead of _readableState.ended, so a server-initiated push stream that ends cleanly is no longer misclassified as an abort. Also fix a regression from the settable high-water-mark setter: its validation made new IncomingMessage(<truthy non-socket>) throw ERR_INVALID_ARG_VALUE, so http/incoming.js now only syncs the socket HWM when it is defined. Non-streams-core _readableState/_writableState references: 43 -> 17.
mcollina
force-pushed
the
refactor/stream-state-accessors
branch
from
November 22, 2026 08:08
a4033fd to
d47e881
Compare
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.
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.