fix(stream-parser): initialize the readable object-mode buffer - #723
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The new test asserts stream properties (readableObjectMode/writableObjectMode) that are not consistently implemented by readable-stream in this repo, making the test likely brittle or failing.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR fixes StreamParser backpressure by constructing N3StreamParser with readableObjectMode: true so the readable high-water mark is initialized in object units (preventing the readable buffer from defaulting to a 16,384 “object” threshold after toggling object mode post-construction).
Changes:
- Initialize
N3StreamParserwithreadableObjectMode: trueatsuper(...)time to get the correct object-mode high-water mark. - Add a regression test that pipes many single-triple chunks without consuming output and asserts unread-quad buffering stays bounded.
File summaries
| File | Description |
|---|---|
| src/N3StreamParser.js | Initializes the readable side in object mode via super({ ..., readableObjectMode: true }) to fix backpressure thresholds. |
| test/N3StreamParser-test.js | Adds a backpressure regression test to ensure unread quad buffering is bounded by the object-mode high-water mark. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Initialize the readable high-water mark through the public object-mode constructor option. Cover bounded unread quads and assert readableHighWaterMark directly.
3e35223 to
98cbfdc
Compare
|
🎉 This PR is included in version 2.7.7 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Construct
StreamParserwithreadableObjectMode: trueso its readable high-water mark is initialized in objects. Previously the constructor initialized a byte-mode buffer, then changed the private object-mode flag; that left the threshold at 16,384 quads instead of the normal 16-object default. Writable input remains in byte mode.A regression test pipes 30,000 one-triple chunks into a parser without consuming the output. It checks
readableHighWaterMarkdirectly and verifies that the source pauses with at most 16 queued quads. The revised test fails against unfixed main with a high-water mark of 16,384 and passes after the patch. The high-water mark is a buffering threshold; a single large input chunk can still produce more quads synchronously.Validation: all 6,892 tests pass with 100% coverage; ESLint, Node/browser builds, and
git diff --checkpass.This fixes pre-existing behavior on
mainand is independent of #721. The base includes the mergedimport()backpressure change from #724 and the lexer optimization from #725.