diff --git a/lib/internal/streams/iter/utils.js b/lib/internal/streams/iter/utils.js index ca3d2531d6f9e0..be9e3833e0b040 100644 --- a/lib/internal/streams/iter/utils.js +++ b/lib/internal/streams/iter/utils.js @@ -190,15 +190,14 @@ function toUint8Array(chunk) { } /** - * Check if all chunks in an array are already Uint8Array (no strings). - * Short-circuits on the first string found. + * Check if all chunks in an array are already Uint8Array. + * Short-circuits on the first non-Uint8Array chunk found. * @param {Array} chunks * @returns {boolean} */ function allUint8Array(chunks) { - // Ok, well, kind of. This is more a check for "no strings"... for (let i = 0; i < chunks.length; i++) { - if (typeof chunks[i] === 'string') return false; + if (!isUint8Array(chunks[i])) return false; } return true; } diff --git a/test/parallel/test-stream-iter-push-writer.js b/test/parallel/test-stream-iter-push-writer.js index e617a8a5309dae..f085f465951449 100644 --- a/test/parallel/test-stream-iter-push-writer.js +++ b/test/parallel/test-stream-iter-push-writer.js @@ -171,6 +171,28 @@ async function testWritevSync() { assert.strictEqual(result, 'hello'); } +async function testWritevSyncInvalidChunkDoesNotQueue() { + const { writer, readable } = push({ highWaterMark: 10 }); + + assert.throws( + () => writer.writevSync([1]), + { code: 'ERR_INVALID_ARG_TYPE' }, + ); + + const iter = readable[Symbol.asyncIterator](); + const next = iter.next(); + const result = await Promise.race([ + next.then(() => 'resolved'), + new Promise((resolve) => setImmediate(resolve, 'pending')), + ]); + assert.strictEqual(result, 'pending'); + + writer.endSync(); + const end = await next; + assert.strictEqual(end.value, undefined); + assert.strictEqual(end.done, true); +} + async function testWritevMixedTypes() { const { writer, readable } = push({ highWaterMark: 10 }); // Mix strings and Uint8Arrays @@ -494,6 +516,7 @@ Promise.all([ testOndrainRejectsOnConsumerThrow(), testWritev(), testWritevSync(), + testWritevSyncInvalidChunkDoesNotQueue(), testWritevMixedTypes(), testWriteAfterEnd(), testWriteAfterFail(),