Skip to content

fix: prevent silent failures when releasing stream reader locks#3397

Closed
meenaksh06 wants to merge 1 commit intotriggerdotdev:mainfrom
meenaksh06:fix/release-lock-error-handling
Closed

fix: prevent silent failures when releasing stream reader locks#3397
meenaksh06 wants to merge 1 commit intotriggerdotdev:mainfrom
meenaksh06:fix/release-lock-error-handling

Conversation

@meenaksh06
Copy link
Copy Markdown

Closes #

✅ Checklist

  • I have followed every step in the contributing guide
  • The PR title follows the convention
  • I ran and tested the code works

Testing

  • Verified that calling reader.releaseLock() does not crash the application when an error occurs.
  • Simulated edge cases where the reader is already released or invalid.
  • Confirmed that errors are handled gracefully and logged only when debug mode is enabled.
  • Ensured no impact on existing stream functionality.

Changelog

  • Added error handling for reader.releaseLock() to prevent silent failures.
  • Introduced conditional debug logging for better observability.
  • Improved consistency in stream handling logic.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 16, 2026

⚠️ No Changeset found

Latest commit: 4d1141f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

Hi @meenaksh06, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details.

@github-actions github-actions Bot closed this Apr 16, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 16, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 06a58b80-6042-4c23-bce9-08c8e8cb4631

📥 Commits

Reviewing files that changed from the base of the PR and between 0c33de8 and 4d1141f.

📒 Files selected for processing (3)
  • packages/core/src/v3/realtimeStreams/streamInstance.ts
  • packages/core/src/v3/realtimeStreams/streamsWriterV1.ts
  • packages/core/src/v3/realtimeStreams/streamsWriterV2.ts

Walkthrough

Updates three stream handler files to conditionally emit console warnings when reader.releaseLock() fails during stream cleanup operations. Previously, lock release errors were silently swallowed in catch blocks. The new behavior adds a console.warn("Failed to release stream reader lock", error) call conditional on a debug flag being truthy, introducing a debug identifier dependency within each safeReleaseLock implementation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 4 potential issues.

View 1 additional finding in Devin Review.

Open in Devin Review

Comment on lines +157 to +160
if (debug) {
// fallback if no logger available
console.warn("Failed to release stream reader lock", error);
}
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.

🔴 Undefined debug variable in safeReleaseLock causes ReferenceError, defeating error safety

safeReleaseLock is a standalone module-level function, not a class method. The new code references debug in the catch block (if (debug)), but debug is never declared, imported, or passed as a parameter in this file. If reader.releaseLock() throws, the catch block will itself throw a ReferenceError: debug is not defined, converting a safely-caught error into an uncaught crash — the exact opposite of the function's purpose.

Suggested change
if (debug) {
// fallback if no logger available
console.warn("Failed to release stream reader lock", error);
}
if (typeof debug !== "undefined" && debug) {
// fallback if no logger available
console.warn("Failed to release stream reader lock", error);
}
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +468 to +471
if (debug) {
// fallback if no logger available
console.warn("Failed to release stream reader lock", error);
}
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.

🔴 Undefined debug variable in safeReleaseLock causes ReferenceError, defeating error safety

Same issue as in streamInstance.ts. The standalone safeReleaseLock function references debug which is not in scope. The StreamsWriterV1 class has no debug property at all, and even if it did, this is not a class method so this.debug is inaccessible. If releaseLock() throws, the catch handler will crash with ReferenceError.

Suggested change
if (debug) {
// fallback if no logger available
console.warn("Failed to release stream reader lock", error);
}
if (typeof debug !== "undefined" && debug) {
// fallback if no logger available
console.warn("Failed to release stream reader lock", error);
}
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +216 to +219
if (debug) {
// fallback if no logger available
console.warn("Failed to release stream reader lock", error);
}
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.

🔴 Undefined debug variable in safeReleaseLock causes ReferenceError, defeating error safety

Same issue as the other two files. The StreamsWriterV2 class has private readonly debug: boolean at line 52, but the standalone safeReleaseLock function at module scope cannot access class instance properties. The reference to bare debug at line 216 will throw ReferenceError if releaseLock() fails.

Suggested change
if (debug) {
// fallback if no logger available
console.warn("Failed to release stream reader lock", error);
}
if (typeof debug !== "undefined" && debug) {
// fallback if no logger available
console.warn("Failed to release stream reader lock", error);
}
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines 464 to 473
function safeReleaseLock(reader: ReadableStreamDefaultReader<any>) {
try {
reader.releaseLock();
} catch (error) {}
} catch (error) {
if (debug) {
// fallback if no logger available
console.warn("Failed to release stream reader lock", error);
}
}
}
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.

🚩 Design consideration: safeReleaseLock has no access to debug context

Even after fixing the ReferenceError, the underlying design issue remains: safeReleaseLock is a standalone function with no way to know whether debug mode is enabled. In streamsWriterV2.ts, the class has this.debug (streamsWriterV2.ts:52), and in streamInstance.ts, the options have debug (streamInstance.ts:17), but streamsWriterV1.ts has no debug concept at all. A clean fix would either: (a) pass debug as a parameter to safeReleaseLock, (b) always log the warning unconditionally (it's in a catch block so it only fires on errors), or (c) extract it to a shared util that accepts a debug flag.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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.

1 participant