GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stream: fix Writable.toWeb() hang on synchronous drain · nodejs/node@dc57173

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/webstreams
    • adapters.js
  • test/parallel
    • test-whatwg-webstreams-adapters-to-writablestream.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/webstreams/adapters.js‎

Copy file name to clipboardExpand all lines: lib/internal/webstreams/adapters.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ function newWritableStreamFromStreamWritable(streamWritable, options = kEmptyObj
232232
}
233233
if (streamWritable.writableNeedDrain || !streamWritable.write(chunk)) {
234234
backpressurePromise = PromiseWithResolvers();
235+
if (!streamWritable.writableNeedDrain) {
236+
backpressurePromise.resolve();
237+
}
235238
return SafePromisePrototypeFinally(
236239
backpressurePromise.promise, () => {
237240
backpressurePromise = undefined;
Collapse file

‎test/parallel/test-whatwg-webstreams-adapters-to-writablestream.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-webstreams-adapters-to-writablestream.js
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,26 @@ class TestWritable extends Writable {
197197
assert.strictEqual(chunk, arrayBuffer);
198198
}));
199199
}
200+
201+
{
202+
// Test that the stream doesn't hang when the underlying Writable
203+
// emits 'drain' synchronously during write().
204+
// Fixes: https://github.com/nodejs/node/issues/61145
205+
const writable = new Writable({
206+
write(chunk, encoding, callback) {
207+
callback();
208+
},
209+
});
210+
211+
// Force synchronous 'drain' emission during write()
212+
// to simulate a stream that doesn't have Node.js's built-in kSync protection.
213+
writable.write = function(chunk) {
214+
this.emit('drain');
215+
return false;
216+
};
217+
218+
const writableStream = newWritableStreamFromStreamWritable(writable);
219+
const writer = writableStream.getWriter();
220+
writer.write(new Uint8Array([1, 2, 3])).then(common.mustCall());
221+
writer.write(new Uint8Array([4, 5, 6])).then(common.mustCall());
222+
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.