Skip to content

fix: clean up stream abort listeners#1884

Open
pragnyanramtha wants to merge 1 commit into
openai:masterfrom
pragnyanramtha:pragnyan/cleanup-stream-abort-listeners
Open

fix: clean up stream abort listeners#1884
pragnyanramtha wants to merge 1 commit into
openai:masterfrom
pragnyanramtha:pragnyan/cleanup-stream-abort-listeners

Conversation

@pragnyanramtha
Copy link
Copy Markdown

Summary

  • centralize EventStream caller AbortSignal forwarding so listener references are retained
  • remove forwarded abort listeners when streams end
  • update chat, responses, and assistant stream helpers to use the shared cleanup
  • add a ChatCompletionStream regression for listener registration and removal after completion

Why

Stream helpers currently attach anonymous abort listeners to caller-provided signals and never remove them. This can retain timer-backed signals such as AbortSignal.timeout() after the stream completes, similar to the client-level fetchWithTimeout leak but in the helper layer.

Validation

  • yarn test tests/lib/ChatCompletionStream.test.ts --runInBand -t 'removes the caller abort listener'
  • yarn test tests/lib/ChatCompletionStream.test.ts tests/lib/ResponseStream.test.ts tests/streaming/assistants/assistant.test.ts --runInBand
  • ./node_modules/.bin/prettier --check src/lib/EventStream.ts src/lib/AbstractChatCompletionRunner.ts src/lib/AssistantStream.ts src/lib/ChatCompletionStream.ts src/lib/responses/ResponseStream.ts tests/lib/ChatCompletionStream.test.ts
  • ./node_modules/.bin/eslint src/lib/EventStream.ts src/lib/AbstractChatCompletionRunner.ts src/lib/AssistantStream.ts src/lib/ChatCompletionStream.ts src/lib/responses/ResponseStream.ts tests/lib/ChatCompletionStream.test.ts
  • ./scripts/build
  • git diff --check

@pragnyanramtha pragnyanramtha marked this pull request as ready for review May 16, 2026 23:18
@pragnyanramtha pragnyanramtha requested a review from a team as a code owner May 16, 2026 23:18
Copilot AI review requested due to automatic review settings May 16, 2026 23:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

2 participants