Skip to content

Clean up abort signal listeners#1956

Open
fallintoplace wants to merge 1 commit into
openai:mainfrom
fallintoplace:fix/remove-abort-listener
Open

Clean up abort signal listeners#1956
fallintoplace wants to merge 1 commit into
openai:mainfrom
fallintoplace:fix/remove-abort-listener

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • keep caller-provided abort signals connected after response headers arrive
  • remove the abort listener after SDK-owned body consumption finishes or is cancelled
  • add regression coverage for normal body parsing, aborting during a pending body read, and streamed response iteration

Why

fetchWithTimeout() previously cleaned up the abort listener as soon as fetch() resolved. That avoided the listener leak, but it also disconnected caller aborts while APIPromise was still parsing the response body or while a stream was being consumed.

This keeps the listener attached through body consumption, then removes it from the parse and stream finalization paths.

Tests

  • ./node_modules/.bin/jest tests/index.test.ts --runInBand
  • ./node_modules/.bin/prettier --check src/client.ts src/internal/parse.ts src/core/streaming.ts tests/index.test.ts
  • ./node_modules/.bin/eslint src/client.ts src/internal/parse.ts src/core/streaming.ts tests/index.test.ts
  • ./node_modules/typescript/bin/tsc
  • ./scripts/build

@fallintoplace fallintoplace requested a review from a team as a code owner June 23, 2026 19:14

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2cc24f06d3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/client.ts Outdated
return await this.fetch.call(undefined, url, fetchOptions);
} finally {
clearTimeout(timeout);
if (signal) signal.removeEventListener('abort', abort);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep abort signal attached until the body is consumed

This finally runs as soon as fetch resolves with response headers, but APIPromise parses the body later in defaultParseResponse and streaming responses are consumed even later. If a caller aborts their request signal after headers arrive (for example while waiting on a slow JSON body or while iterating a streamed response), this listener has already been removed, so the internal controller passed to fetch is never aborted and the body read/stream continues instead of cancelling.

Useful? React with 👍 / 👎.

@fallintoplace fallintoplace force-pushed the fix/remove-abort-listener branch from 2cc24f0 to e436581 Compare June 23, 2026 19:25
@HAYDEN-OAI HAYDEN-OAI added the upstream Needs to be addressed in Stainless upstream label Jun 23, 2026 — with ChatGPT Codex Connector
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

upstream Needs to be addressed in Stainless upstream

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants