Skip to content

Closed WritableStream causes ERR_INTERNAL_ASSERTION #57272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ayonli opened this issue Mar 2, 2025 · 2 comments · Fixed by #57280
Closed

Closed WritableStream causes ERR_INTERNAL_ASSERTION #57272

ayonli opened this issue Mar 2, 2025 · 2 comments · Fixed by #57280

Comments

@ayonli
Copy link

ayonli commented Mar 2, 2025

Version

v22.14.0

Platform

Darwin mba.local 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:41 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T8103 arm64

Subsystem

Web Streams

What steps will reproduce the bug?

const writable = new WritableStream({
    write(chunk) {
        console.log(chunk)
    }
})

const writer = writable.getWriter()

await writer.write('Hello')
await writer.close() // closes the stream

try {
    await writer.write('World') // write after closed
} catch (e) {
    console.error(e)
}

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

When this program runs, it should print something like the following:

Hello
TypeError [ERR_INVALID_STATE]: Invalid state: WritableStream is closed
    at writableStreamDefaultWriterWrite (node:internal/webstreams/writablestream:997:7)
    at WritableStreamDefaultWriter.write (node:internal/webstreams/writablestream:442:12)
    at <anonymous> (/Users/ayon/Workspace/try-out/main2.ts:14:18) {
  code: 'ERR_INVALID_STATE'
}

The correct behavior is that after the stream is closed, continuing to write will cause a TypeError saying that the stream is closed.

What do you see instead?

Instead, the new version of Node.js v22.14.0 prints this:

Hello
Error [ERR_INTERNAL_ASSERTION]: This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

    at assert (node:internal/assert:11:11)
    at writableStreamDefaultControllerGetChunkSize (node:internal/webstreams/writablestream:1184:5)
    at writableStreamDefaultWriterWrite (node:internal/webstreams/writablestream:983:21)
    at WritableStreamDefaultWriter.write (node:internal/webstreams/writablestream:443:12)
    at <anonymous> (/Users/ayon/Workspace/try-out/main2.ts:13:18) {
  code: 'ERR_INTERNAL_ASSERTION'
}

Additional information

The correct behavior is consistent with Deno, Bun, the browser, and previous Node.js versions, i.e. v22.13.1 and before, but recent versions, such as v22.14.0, are broken.

@aduh95
Copy link
Contributor

aduh95 commented Mar 2, 2025

/cc @nodejs/whatwg-stream

aduh95 pushed a commit that referenced this issue Mar 9, 2025
Signed-off-by: Daeyeon Jeong <[email protected]>
PR-URL: #57280
Fixes: #57272
Refs: #56067
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Jason Zhang <[email protected]>
aduh95 pushed a commit that referenced this issue Mar 9, 2025
Signed-off-by: Daeyeon Jeong <[email protected]>
PR-URL: #57280
Fixes: #57272
Refs: #56067
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Jason Zhang <[email protected]>
RafaelGSS pushed a commit that referenced this issue Apr 1, 2025
Signed-off-by: Daeyeon Jeong <[email protected]>
PR-URL: #57280
Fixes: #57272
Refs: #56067
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Jason Zhang <[email protected]>
RafaelGSS pushed a commit that referenced this issue Apr 1, 2025
Signed-off-by: Daeyeon Jeong <[email protected]>
PR-URL: #57280
Fixes: #57272
Refs: #56067
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Jason Zhang <[email protected]>
aduh95 pushed a commit that referenced this issue Apr 2, 2025
Signed-off-by: Daeyeon Jeong <[email protected]>
PR-URL: #57280
Fixes: #57272
Refs: #56067
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Jason Zhang <[email protected]>
aduh95 pushed a commit that referenced this issue Apr 3, 2025
Signed-off-by: Daeyeon Jeong <[email protected]>
PR-URL: #57280
Fixes: #57272
Refs: #56067
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Jason Zhang <[email protected]>
RafaelGSS pushed a commit that referenced this issue Apr 16, 2025
Signed-off-by: Daeyeon Jeong <[email protected]>
PR-URL: #57280
Fixes: #57272
Refs: #56067
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Jason Zhang <[email protected]>
RafaelGSS pushed a commit that referenced this issue Apr 17, 2025
Signed-off-by: Daeyeon Jeong <[email protected]>
PR-URL: #57280
Fixes: #57272
Refs: #56067
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Jason Zhang <[email protected]>
RafaelGSS pushed a commit that referenced this issue May 1, 2025
Signed-off-by: Daeyeon Jeong <[email protected]>
PR-URL: #57280
Fixes: #57272
Refs: #56067
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Jason Zhang <[email protected]>
RafaelGSS pushed a commit that referenced this issue May 2, 2025
Signed-off-by: Daeyeon Jeong <[email protected]>
PR-URL: #57280
Fixes: #57272
Refs: #56067
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Jason Zhang <[email protected]>
@ayonli
Copy link
Author

ayonli commented May 6, 2025

@aduh95 Now Node.js v20.19 (include 20.19.0 and 20.19.1) also reports this bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants