- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 695
fix: prevent enqueuing into closed ReadableStream #1781
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
fix: prevent enqueuing into closed ReadableStream #1781
Conversation
🦋 Changeset detectedLatest commit: ae3425d The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughThe changes add a private boolean property Changes
Assessment against linked issues
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🔇 Additional comments (2)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
🧩 Analysis chainI'll review this PR for you. Let me gather more information about the changes first. 🏁 Script executed:
Length of output: 209 I need to first check out the PR to properly review the changes. Let me try again. 🏁 Script executed:
Length of output: 272 🏁 Script executed:
Length of output: 6943 @CodeMan62: Yes, this PR looks excellent. The changes properly address the issue of enqueueing data into closed ReadableStreams by:
These changes will effectively prevent the "Cannot enqueue a chunk into a closed readable stream" error that was occurring after 5-15 minutes of operation. ✅ Actions performedComments resolved. |
@ericallam can you check this PR and tell me if there is any problem in it |
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.
Pull Request Overview
This PR fixes an issue where data was being enqueued into a closed ReadableStream, which caused errors after prolonged stream usage. The changes introduce a new #isStreamClosed flag to track stream state, update the stop() and cancel() handlers to set the flag, and add conditional checks before enqueueing messages and final rows.
Comments suppressed due to low confidence (2)
packages/core/src/v3/apiClient/stream.ts:158
- [nitpick] Consider checking the stream closed state inside the loop when enqueuing each row to ensure that no final row is added after the stream is closed, even if the flag changes during iteration.
if (!this.#isStreamClosed) {
packages/core/src/v3/apiClient/stream.ts:114
- [nitpick] The cancel handler duplicates cleanup logic already present in stop(); consider refactoring the shared cleanup into a separate method to reduce code duplication and potential maintenance issues.
cancel: () => {
Closes #1751
✅ Checklist
Testing
pnpm run test --filter @trigger.dev/core
Changelog
#isStreamClosed
flag to track stream statecancel
handlerstop()
methodScreenshots
N/A - This is a backend fix for stream handling, no UI changes.
💯
Summary by CodeRabbit
Bug Fixes
ReadableStream
.Refactor