Skip to content

fix(teeny-request): avoid MaxListenersExceededWarning in stream mode - #9254

Open
re-taro wants to merge 1 commit into
googleapis:mainfrom
re-taro:fix/teeny-request-max-listeners-warning
Open

fix(teeny-request): avoid MaxListenersExceededWarning in stream mode#9254
re-taro wants to merge 1 commit into
googleapis:mainfrom
re-taro:fix/teeny-request-max-listeners-warning

Conversation

@re-taro

@re-taro re-taro commented Sep 5, 2026

Copy link
Copy Markdown

node-fetch v3 attaches several internal pipeline listeners to the
response body stream. Combined with teeny-request's own error forwarding
and pipeline wiring plus downstream consumers such as
@google-cloud/storage, the default limit of 10 listeners is legitimately
exceeded, emitting two MaxListenersExceededWarning messages on every
streamed download. This change removes the listener limit on the fetch
response body stream, which is internal to teeny-request and
short-lived.

Fixes #9185

node-fetch v3 attaches several internal pipeline listeners to the
response body stream. Combined with teeny-request's own error forwarding
and pipeline wiring plus downstream consumers such as
@google-cloud/storage, the default limit of 10 listeners is legitimately
exceeded, emitting two MaxListenersExceededWarning messages on every
streamed download. This change removes the listener limit on the fetch
response body stream, which is internal to teeny-request and
short-lived.

Fixes googleapis#9185

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request addresses an issue where node-fetch v3's internal pipeline listeners exceed the default limit of 10, causing warnings on streamed responses. It resolves this by setting the maximum listeners of the response stream to 0 and adds a corresponding test. The review feedback suggests defensively checking if responseStream is defined and if setMaxListeners is a function before calling it to prevent potential TypeError runtime crashes.

// legitimately exceed the default limit of 10, warning on every
// streamed response
// see: https://github.com/googleapis/google-cloud-node/issues/9185
responseStream.setMaxListeners(0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Calling setMaxListeners directly on responseStream can throw a TypeError if responseStream is null/undefined, or if it is a non-Node stream (such as a Web ReadableStream in isomorphic/browser environments or certain mock streams) that does not implement setMaxListeners.

To prevent potential runtime crashes, we should defensively check if responseStream is defined and if setMaxListeners is a function before calling it.

        if (responseStream && typeof responseStream.setMaxListeners === 'function') {
          responseStream.setMaxListeners(0);
        }

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 this pull request may close these issues.

storage 8.0.1: MaxListenersExceededWarning (11 error/close listeners on PassThrough) on every createReadStream()

1 participant