Skip to content

Commit 6b47004

Browse files
committed
test(node): drop Readable.toWeb crash tests now fixed in Node 26.10
Node 26.10 fixed the uncatchable ERR_INVALID_STATE crash when a Readable.toWeb stream is cancelled mid-upload (nodejs/node#62773), so the tests asserting that the bare adapter crashes started failing on Node 26. Remove them and note the upstream fix on toWebReadableStream, which stays until every supported Node release has it.
1 parent cc041e5 commit 6b47004

2 files changed

Lines changed: 11 additions & 30 deletions

File tree

‎packages/node/src/utils.test.ts‎

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ describe('toWebReadableStream', () => {
323323
/**
324324
* Below the 256 KiB flood chunk, so the consumer cancels on its first read
325325
* while the request is still streaming — the condition that crashes a bare
326-
* `Readable.toWeb`.
326+
* `Readable.toWeb` before Node 26.10.
327327
*/
328328
const LIMIT = 64 * 1024
329329

@@ -437,21 +437,19 @@ describe('toWebReadableStream', () => {
437437
}
438438

439439
/**
440-
* Boots a server that spools each request body via `wrap`, fires `iterations`
441-
* aborted uploads at it, and reports how many completed plus any crashes.
442-
* `stopOnCrash` ends the flood at the first crash.
440+
* Boots a server that spools each request body via `toWebReadableStream`,
441+
* fires `iterations` aborted uploads at it, and reports how many completed
442+
* plus any crashes.
443443
*/
444444
async function runUploadServer(
445445
kind: 'http1' | 'http2',
446-
wrap: (req: Readable) => ReadableStream<Uint8Array>,
447446
iterations: number,
448-
stopOnCrash = false,
449447
): Promise<{ handled: number, crashes: Error[] }> {
450448
const tmpDir = await mkdtemp(path.join(tmpdir(), `toweb-${kind}-`))
451449
let handled = 0
452450

453451
const listener = async (req: any, res: any): Promise<void> => {
454-
await spoolUntilRejected(wrap(req), tmpDir)
452+
await spoolUntilRejected(toWebReadableStream(req), tmpDir)
455453
handled++
456454
try {
457455
if (!res.headersSent) {
@@ -467,13 +465,10 @@ describe('toWebReadableStream', () => {
467465
const server = kind === 'http1' ? createServer(listener) : createHttp2Server(listener)
468466
const flood = kind === 'http1' ? floodAndAbortHttp1 : floodAndAbortHttp2
469467

470-
const crashes = await recordUncaught(async (crashes) => {
468+
const crashes = await recordUncaught(async () => {
471469
await new Promise<void>(resolve => server.listen(0, resolve))
472470
const { port } = server.address() as AddressInfo
473471
for (let i = 0; i < iterations; i++) {
474-
if (stopOnCrash && crashes.length) {
475-
break
476-
}
477472
await flood(port)
478473
await new Promise(resolve => setTimeout(resolve, 5))
479474
}
@@ -484,9 +479,6 @@ describe('toWebReadableStream', () => {
484479
return { handled, crashes }
485480
}
486481

487-
const bare = (req: Readable): ReadableStream<Uint8Array> => Readable.toWeb(req) as ReadableStream<Uint8Array>
488-
const wrapped = (req: Readable): ReadableStream<Uint8Array> => toWebReadableStream(req)
489-
490482
it('converts a raw buffer stream and preserves its bytes as copies', async () => {
491483
const chunks = [Buffer.from('hello '), Buffer.from('world'), Buffer.alloc(1024, 7)]
492484
const source = Readable.from(chunks)
@@ -524,29 +516,15 @@ describe('toWebReadableStream', () => {
524516
expect(source.destroyed).toBe(true) // cancellation still tears the source down
525517
})
526518

527-
it('lets a bare Readable.toWeb crash an aborted HTTP/1 upload (documents the bug)', async () => {
528-
const { crashes } = await runUploadServer('http1', bare, 25, true)
529-
530-
expect(crashes.length).toBeGreaterThan(0)
531-
expect(crashes[0]).toMatchObject({ code: 'ERR_INVALID_STATE' })
532-
}, 30_000)
533-
534519
it('keeps an aborted HTTP/1 upload from crashing the process', async () => {
535-
const { handled, crashes } = await runUploadServer('http1', wrapped, 25)
520+
const { handled, crashes } = await runUploadServer('http1', 25)
536521

537522
expect(crashes).toEqual([])
538523
expect(handled).toBe(25)
539524
}, 30_000)
540525

541-
it('lets a bare Readable.toWeb crash an aborted HTTP/2 upload (documents the bug)', async () => {
542-
const { crashes } = await runUploadServer('http2', bare, 25, true)
543-
544-
expect(crashes.length).toBeGreaterThan(0)
545-
expect(crashes[0]).toMatchObject({ code: 'ERR_INVALID_STATE' })
546-
}, 30_000)
547-
548526
it('keeps an aborted HTTP/2 upload from crashing the process', async () => {
549-
const { handled, crashes } = await runUploadServer('http2', wrapped, 25)
527+
const { handled, crashes } = await runUploadServer('http2', 25)
550528

551529
expect(crashes).toEqual([])
552530
expect(handled).toBe(25)

‎packages/node/src/utils.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import { IncomingMessage } from 'node:http'
1414
* after cancel. The per-chunk copy detaches chunks from Node's pooled `Buffer`
1515
* memory.
1616
*
17+
* Fixed upstream in Node 26.10 (nodejs/node#62773); switch back to
18+
* `Readable.toWeb` once every supported Node release has the fix.
19+
*
1720
* Cancel destroys the source, except http1 server requests: they share their
1821
* socket with the response, so destroying them would kill an in-flight
1922
* response. They are abandoned instead — stalled by backpressure and reclaimed

0 commit comments

Comments
 (0)