Skip to content
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

@tus/s3-store: fix unhandled promise rejection #728

Merged
merged 3 commits into from
Mar 13, 2025
Merged

Conversation

Murderlon
Copy link
Member

@Murderlon Murderlon commented Feb 25, 2025

Ref: #722

Referencing the issue instead of closing it as it also discusses letting stores handle context cancellation (which frees a lock) instead of handlers. I'm not sure whether this is needed yet so not closing the issue but this PR does fix a bug.

@Murderlon Murderlon self-assigned this Feb 25, 2025
Copy link

changeset-bot bot commented Feb 25, 2025

🦋 Changeset detected

Latest commit: 7b3f8de

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@tus/s3-store Patch

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

Copy link

coderabbitai bot commented Feb 25, 2025

Walkthrough

The PR patches the S3Store module by improving error and promise management during multipart uploads. It ensures that upload part failures are fully handled by explicitly destroying streams, catching errors during permit releases, and waiting for all promises to settle. Additionally, the PR introduces a pretest script to compile TypeScript files before running tests and updates test cases (including syntax refactoring and an added failure scenario) to improve coverage.

Changes

File(s) Summary
.changeset/twenty-crews-punch.md
packages/s3-store/.../index.ts
Enhanced error handling & promise management during part uploads by ensuring errors are properly propagated, streams are destroyed on failure, and all promises are awaited using Promise.allSettled.
packages/s3-store/.../test/index.ts Refactored test cases to use arrow functions and added a new test to simulate and verify behavior when multiple concurrent part uploads include failures.
packages/s3-store/package.json Added a “pretest” script (tsc --build) to compile TypeScript before running tests.

Possibly related PRs


📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f47f371 and 7b3f8de.

📒 Files selected for processing (4)
  • .changeset/twenty-crews-punch.md (1 hunks)
  • packages/s3-store/package.json (1 hunks)
  • packages/s3-store/src/index.ts (2 hunks)
  • packages/s3-store/test/index.ts (2 hunks)
🔇 Additional comments (9)
packages/s3-store/package.json (1)

19-19: Good addition of a pretest script.

Adding the TypeScript compilation step before running tests ensures that you catch any TypeScript errors before the tests run, improving the development workflow.

.changeset/twenty-crews-punch.md (1)

1-5: Clear and concise description of the patch.

The changeset clearly explains the issue being fixed: an unhandled promise rejection when uploading a part fails. This aligns well with the code changes in the S3Store class.

packages/s3-store/src/index.ts (4)

412-414: Good enhancement of error handling.

When an error occurs during part upload, destroying the splitterStream with the error stops further chunk processing, preventing additional failures and resource consumption.


419-421: Proper error handling for permit release.

Adding a catch block to ignore errors during permit release prevents unhandled promise rejections from propagating. This is a safe approach since a failure to release a permit doesn't affect the upload result.


428-430: Consistent error handling pattern applied.

The same error handling pattern is correctly applied to the chunkError event handler, ensuring consistency in how permit releases are handled.


446-450: Improved promise management ensures completeness.

Using Promise.allSettled(promises) before Promise.all(promises) is an excellent approach. It ensures all promises are allowed to complete (preventing background processing), while still maintaining the rejection behavior for error handling. The comments clearly explain this pattern.

packages/s3-store/test/index.ts (3)

281-286: Style update to arrow functions.

Converting to arrow functions makes the code more consistent with modern JavaScript practices and aligns with the rest of the codebase style.


288-295: Style update for consistency.

Similar to the previous test, this has been converted to an arrow function for consistency.


297-327: Excellent test case for concurrent upload failures.

This test directly addresses the bug fix by simulating a failure during concurrent part uploads. It properly tests that:

  1. The error is propagated when a part upload fails
  2. The upload process stops correctly after a failure
  3. No more parts are attempted after a failure

This is a crucial test that verifies the robustness of your promise handling improvements.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@mitjap
Copy link
Collaborator

mitjap commented Feb 25, 2025

I also have fix for this. I will create draft PR so we can compare solutions.

@Murderlon
Copy link
Member Author

I also have fix for this. I will create draft PR so we can compare solutions.

Sounds good, this is not done yet anyway

@Murderlon
Copy link
Member Author

@mitjap I want to release the major version soon. Should I take this over the finish line, do a release, and then a major release or are you showing your version soon?

@Murderlon Murderlon marked this pull request as ready for review March 12, 2025 13:55
@Murderlon Murderlon merged commit c8e78bd into main Mar 13, 2025
4 checks passed
@Murderlon Murderlon deleted the s3-unhandled-promise branch March 13, 2025 11:51
Murderlon added a commit that referenced this pull request Mar 13, 2025
* main:
  [ci] release (#721)
  @tus/s3-store: fix unhandled promise rejection (#728)
  Bump @aws-sdk/client-s3 from 3.717.0 to 3.758.0 (#733)
  Bump @types/node from 22.10.1 to 22.13.7 (#734)
  Bump typescript from 5.6.2 to 5.8.2 (#731)
  @tus/azure-store: fix non-ASCII characters error on metadata (#725)
  Fix package-lock.json
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