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 — fix aborting Streams by epistemancering · Pull Request #3754 · nodejs/undici

Conversation

@epistemancering

@epistemancering epistemancering commented Oct 21, 2024

Copy link
Copy Markdown
Contributor

This relates to...

#1711

Rationale

The simple fix to the memory issue caused a worse issue. Common patterns that involve catching AbortErrors, such as retrying slow requests, silently fail if the signal unluckily happens to be aborted during the read. A proper fix to the memory issue will likely be more involved.

Changes

revert 49e33a8

Bug Fixes

Aborting a Stream doesn't throw.

const abortController = new AbortController

;(async () => {
    const readStream = (await fetch("https://www.googleapis.com/customsearch/v1", { signal: abortController.signal })).arrayBuffer()

    setTimeout(() => {
        abortController.abort()
    })

    await readStream
})()

Status

  • I have read and agreed to the Developer's Certificate of Origin
  • Tested
  • Review ready

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@epistemancering
fix aborting Streams
d015c34
KhafraDev
KhafraDev suggested changes Oct 21, 2024
View reviewed changes

@KhafraDev KhafraDev left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing a test and is replacing one issue for another. I will take a look in a few days.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@KhafraDev

KhafraDev commented Oct 28, 2024

Copy link
Copy Markdown
Member

I need a test case that doesn't use a third party endpoint to work on it. The case you provided doesn't abort in node or Deno, and I cannot test in browsers because of CSP.

The correct fix, afaict, is to remove the previous listener if > 1 exists (such that 1 listener always exists) or to only add a listener if there are none.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@epistemancering
stop memory leak
4a0a7cd
@epistemancering

epistemancering commented Oct 29, 2024

Copy link
Copy Markdown
Contributor Author
import * as http from "http"

const abortStream = async () => {
    const abortController = new AbortController
    const readStream = (await fetch("http://localhost", { signal: abortController.signal })).arrayBuffer()
    abortController.abort()
    console.log(await readStream)
}

http.createServer((request, response) => {
    if (request.url?.[1]) {
        response.setHeader("content-type", "text/html")

        response.end(`<!doctypehtml>
            <html>
                <body>
                    <script>
                        (${abortStream})()
                    </script>
                </body>
            </html>
        `)
    } else {
        response.end(new Uint8Array(20000))
    }
}).listen(80, abortStream)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

KhafraDev
KhafraDev approved these changes Oct 29, 2024
View reviewed changes
@KhafraDev
KhafraDev merged commit afeb626 into nodejs:main Oct 29, 2024
@KhafraDev

KhafraDev commented Oct 29, 2024

Copy link
Copy Markdown
Member

Thank you!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Dec 3, 2024
[Release] v7.1.0 #3922
Merged
This was referenced Dec 16, 2024
[Release] v7.1.1 #3952
Closed
[Release] v7.2.0 #3962
Merged
This was referenced Jan 9, 2025
fix(deps): update dependency undici to v7 eik-lib/rollup-plugin#220
Closed
fix(deps): update dependency undici to v7 - autoclosed podium-lib/client#447
Closed
fix(deps): update dependency undici to v7 - autoclosed eik-lib/node-client#215
Closed
fix(deps): update dependency undici to v7 eik-lib/esbuild-plugin#189
Merged
chore(deps): update devdependency undici to v7 - autoclosed unjs/ofetch#463
Closed
chore(deps): update devdependency undici to v7 unjs/node-fetch-native#133
Closed
chore(deps): update devdependency undici to v7 - autoclosed h3js/crossws#94
Closed
Update dependency undici to v7 - autoclosed TryGhost/Actions#46
Closed
Update dependency undici to v7 noahm/DDRCardDraw#406
Merged
fix(deps): update dependency undici to v7 podium-lib/http-client#22
Closed
chore(deps): update dependency undici to v7 tinovyatkin/smithy-node-native-fetch#476
Closed
chore(deps): update dependency undici to v7 - abandoned - autoclosed syfxlin/blog#143
Closed
chore(deps): update dependency undici to v7 - autoclosed bitomic/loki#1026
Closed
fix(deps): update dependency undici to v7 eik-lib/webpack-plugin#159
Closed
Update dependency undici to v7 - autoclosed hmiyado/kottage-front#1420
Closed
chore(deps): update dependency undici to v7 prisma/orm#26070
Merged
fix(package): update all dependencies (major) Kadphol/dummy-card-game#3
Open
@github-actions github-actions Bot mentioned this pull request Mar 12, 2025
[Release] v6.21.2 #4092
Closed
@github-actions github-actions Bot mentioned this pull request May 12, 2025
[Release] v6.21.3 #4211
Closed
@coderabbitai coderabbitai Bot mentioned this pull request Jul 1, 2026
feat(add-data): retrieve layers/types for WMS and WFS from GetCapabilities opengeos/GeoLibre#1039
Merged
@pacocartones pacocartones mentioned this pull request Aug 9, 2026
Hangs on await response.text() using AbortController on unidci 6.21.1 #4089
Open
@mrityunjay-pandey mrityunjay-pandey mentioned this pull request Oct 13, 2026
[v6.x] fix(fetch): fix aborting Streams (#3754) #6000
Merged
7 tasks done
@mcollina mcollina mentioned this pull request Oct 13, 2026
[v6.x] fix(fetch): error the stream when decompression fails after onComplete #6001
Open
3 of 7 tasks
mcollina added a commit to mcollina/undici that referenced this pull request Oct 13, 2026
@mcollina
fix(fetch): error the stream when decompression fails after onComplete
0e56553
The body pull loop runs decompression after onComplete has already
fired, but onComplete removed the fetch controller's 'terminated'
listener (onAborted). When zlib fails (e.g. a response declares
content-encoding: gzip but the body is not valid gzip), controller
termination never reaches the response stream, so text(), json() and
stream reads hang forever and the AbortSignal cannot end them.

Register the onAborted listener only once per fetch (guarded by the
presence of fetchParams.controller.resume) and stop removing it in
onComplete. This keeps the listener alive until the fetch settles so a
late decompression failure correctly errors the stream, while avoiding
the MaxListenersExceededWarning on redirects that the single
registration prevents.

Fixes nodejs#5999

Backport of nodejs#3754.

Refs: nodejs#3754
mcollina pushed a commit that referenced this pull request Oct 14, 2026
@mrityunjay-pandey @epistemancering
[v6.x] fix(fetch): fix aborting Streams (#3754) (#6000)
407630a
* fix aborting Streams (#3754)

* fix aborting Streams

* stop memory leak

(cherry picked from commit afeb626)

* test: add regression test for invalid compressed fetch body

A response that advertises content-encoding: gzip but delivers a body
that is not valid gzip in a later packet than the headers left the
body stream pending forever, because the 'terminated' listener had
already been removed in onComplete.

Refs: #5999

---------

Co-authored-by: Austin Henrie <[email protected]>
mcollina added a commit to mcollina/undici that referenced this pull request Oct 14, 2026
@mcollina
fix(fetch): error the stream when decompression fails after onComplete
f6251fc
The body pull loop runs decompression after onComplete has already
fired, but onComplete removed the fetch controller's 'terminated'
listener (onAborted). When zlib fails (e.g. a response declares
content-encoding: gzip but the body is not valid gzip), controller
termination never reaches the response stream, so text(), json() and
stream reads hang forever and the AbortSignal cannot end them.

Register the onAborted listener only once per fetch (guarded by the
presence of fetchParams.controller.resume) and stop removing it in
onComplete. This keeps the listener alive until the fetch settles so a
late decompression failure correctly errors the stream, while avoiding
the MaxListenersExceededWarning on redirects that the single
registration prevents.

Fixes nodejs#5999

Backport of nodejs#3754.

Refs: nodejs#3754
@github-actions github-actions Bot mentioned this pull request Oct 15, 2026
[Release] v6.29.1 #6023
Merged
This was referenced Oct 24, 2026
refactor: Bump undici from 6.27.0 to 6.29.1 and 7.28.0 to 7.30.1 parse-community/parse-server-example#947
Merged
refactor: Bump undici from 6.28.1 to 6.29.1, 7.29.1 to 7.30.1 and 7.30.0 to 7.30.1 parse-community/parse-server-sqs-mq-adapter#460
Merged
refactor: Bump undici from 6.29.0 to 6.29.1 and 7.30.0 to 7.30.1 parse-community/parse-server-api-mail-adapter#307
Merged
fix: Bump undici from 6.28.1 to 6.29.1 and 7.29.1 to 7.30.1 parse-community/parse-server-push-adapter#636
Merged
refactor: Bump undici from 6.28.1 to 6.29.1, 7.29.1 to 7.30.1 and 7.30.0 to 7.30.1 parse-community/parse-dashboard#3510
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@KhafraDev KhafraDev KhafraDev approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@epistemancering @KhafraDev
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — 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.