Skip to content

fix(subscriber): await request status updates#3223

Open
fallenbagel wants to merge 1 commit into
developfrom
fix/media-subscriber-unhandled-rejection
Open

fix(subscriber): await request status updates#3223
fallenbagel wants to merge 1 commit into
developfrom
fix/media-subscriber-unhandled-rejection

Conversation

@fallenbagel

@fallenbagel fallenbagel commented Jul 4, 2026

Copy link
Copy Markdown
Member

Description

Similar to #2760, while working on a fix for availability sync job, I noticed that MediaSubscriber's beforeUpdate and afterUpdate call updateChildRequestStatus and updateRelatedMediaRequest without awaiting them, and neither method has its own error handling. Since Seerr has no global unhandledRejection handler, any rejection from either call is silently lost on Node 15+, and an unhandled rejection with no handler terminates the process by
default. Any transient failure in this request-sync path (a DB error, a constraint violation, anything) can crash the running server, not just fail one status update.

This surfaced while working on unrelated availability sync fixes: a test that inserted a real MediaRequest and triggered a status change would intermittently report an unhandled rejection after the test had already completed. The screenshot below shows that failure; the underlying risk is the same in production, just without a test runner around to catch it.

Both calls are now awaited and wrapped in try/catch, so a failure in the request-sync side effect is logged instead of taking down the process, and can't interfere with the primary media save.

image

How Has This Been Tested?

Screenshots / Logs (if applicable)

Checklist:

  • I have read and followed the contribution guidelines.
  • Disclosed any use of AI (see our policy)
  • I have updated the documentation accordingly.
  • All new and existing tests passed.
  • Successful build pnpm build
  • Translation keys pnpm i18n:extract
  • Database migration (if required)

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of related media request status updates during save operations.
    • Added safer handling when status information is missing to prevent update failures.
    • Errors encountered during both 4k and non-4k request updates are now logged for easier troubleshooting.

@fallenbagel fallenbagel requested a review from Copilot July 4, 2026 19:12
@fallenbagel fallenbagel requested a review from a team as a code owner July 4, 2026 19:12
@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 094ae42e-30d3-44b8-b449-3ae09e62bd9a

📥 Commits

Reviewing files that changed from the base of the PR and between 14fea58 and 6df7026.

📒 Files selected for processing (1)
  • server/subscriber/MediaSubscriber.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/subscriber/MediaSubscriber.ts

📝 Walkthrough

Walkthrough

MediaSubscriber now logs failures during beforeUpdate and afterUpdate request-status updates, and afterUpdate uses optional chaining when comparing against prior persisted media status fields.

Changes

MediaSubscriber Error Handling

Layer / File(s) Summary
Logger import and beforeUpdate error handling
server/subscriber/MediaSubscriber.ts
Adds a logger import, returns early when prior media state is missing, and wraps beforeUpdate child MediaRequest status updates in try/catch with error logging.
afterUpdate error handling and safe status checks
server/subscriber/MediaSubscriber.ts
Returns early when prior media state is missing, wraps afterUpdate related/completed request updates in try/catch, and uses optional chaining on event.databaseEntity?.status and ?.status4k for status gating.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • seerr-team/seerr#2462: Also updates MediaSubscriber status-transition handling for related MediaRequest records.

Suggested reviewers: gauthier-th

Poem

A rabbit hopped through try and catch,
With logs to note each failing match.
Old statuses now read with care,
So silent slips no longer snare.
Hop hop — the updates tread more light. 🐇

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: MediaSubscriber now awaits request status updates and handles failures.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

Copilot AI 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.

Pull request overview

Updates the TypeORM MediaSubscriber to prevent unhandled promise rejections during request-status synchronization when Media entities update, avoiding process termination on Node versions where unhandled rejections are fatal.

Changes:

  • Await updateChildRequestStatus in beforeUpdate and wrap in try/catch with logging.
  • Await updateRelatedMediaRequest in afterUpdate and wrap in try/catch with logging.
  • Add @server/logger usage to record failures instead of letting rejections escape.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/subscriber/MediaSubscriber.ts
Comment thread server/subscriber/MediaSubscriber.ts

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@server/subscriber/MediaSubscriber.ts`:
- Around line 188-222: In MediaSubscriber.afterUpdate, the standard and 4K
update paths are incorrectly wrapped in one shared try/catch, so a failure in
one branch prevents the other branch from running. Split the two
updateRelatedMediaRequest calls into separate guarded blocks (or separate
try/catch handling) so the non-4K and 4K updates fail independently, while
keeping the existing logger.error context for each branch.
- Around line 130-152: Split the standard and 4K child-status updates in
MediaSubscriber.beforeUpdate into separate guarded branches so a failure in one
does not prevent the other from running, and add an early check for
event.databaseEntity before accessing its fields. Make sure the logic around
updateChildRequestStatus, event.entity.status/status4k, and
event.databaseEntity.id safely handles cases where databaseEntity is undefined
on some TypeORM update paths, and keep the existing error logging scoped to each
branch.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 82634918-443e-441a-8349-def189f45e57

📥 Commits

Reviewing files that changed from the base of the PR and between d051deb and d97cce4.

📒 Files selected for processing (1)
  • server/subscriber/MediaSubscriber.ts

Comment thread server/subscriber/MediaSubscriber.ts
Comment thread server/subscriber/MediaSubscriber.ts
@fallenbagel fallenbagel force-pushed the fix/media-subscriber-unhandled-rejection branch 2 times, most recently from af927f4 to 14fea58 Compare July 4, 2026 19:45
@seerr-automation-bot seerr-automation-bot added this to the v3.4.0 milestone Jul 4, 2026
updateChildRequestStatus and updateRelatedMediaRequest were called from
beforeUpdate/afterUpdate without being awaited or wrapped in error
handling. Since Seerr registers no unhandledRejection handler, any
rejection from either call falls through to Node's default behaviour,
which terminates the process on Node 15+. Await both calls and wrap them
in try/catch so a failure in the request-sync side effect is logged
instead of crashing the server, and can't affect the primary media save.
@fallenbagel fallenbagel force-pushed the fix/media-subscriber-unhandled-rejection branch from 14fea58 to 6df7026 Compare July 4, 2026 19:59
@fallenbagel fallenbagel enabled auto-merge (squash) July 11, 2026 16:04
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.

3 participants