tus-node-server icon indicating copy to clipboard operation
tus-node-server copied to clipboard

chore(s3-store): replace @shopify/semaphore with async-mutex

Open Emperiusm opened this issue 6 months ago β€’ 4 comments

Why

@shopify/[email protected] was archived by Shopify and surfaces as a Package no longer supported deprecation on every npm install of @tus/s3-store. There is no successor release planned, and downstream projects taking dependency hygiene seriously (e.g. via npm audit / install-log linting) need a path off it.

async-mutex is actively maintained (~17M weekly downloads), MIT-licensed, has zero runtime deps, and exposes a counting Semaphore with an equivalent contract.

What

packages/s3-store/src/index.ts is the only consumer. The diff is small:

-import {Semaphore, type Permit} from '@shopify/semaphore'
+import {Semaphore} from 'async-mutex'

API delta this PR adapts to:

@shopify/semaphore async-mutex
await sem.acquire() returns Permit await sem.acquire() returns [value, releaseFn]
permit.release(): Promise<void> releaseFn(): void (sync)

The previous permit?.release().catch(() => {}) calls were defending against a Promise rejection that async-mutex.release does not have (it's a sync fn that only throws on programmer error β€” over-release of a permit). The .catch no-ops collapse to direct release() calls.

Verified

  • tsc --build is clean for @tus/s3-store after the change.
  • Local mocha dist/test/*.js: the 12 tests that don't need real AWS credentials pass; the 21 Region is missing integration failures are pre-existing and unaffected.

Notes

  • Found via dependency-deprecation cleanup in a downstream consumer (Second Opinion). Filing both the issue context and the patch since the change is small enough to ship together.
  • No semver-major behavior change in @tus/s3-store's public surface β€” only the internal concurrency primitive.

πŸ€– Generated with Claude Code

Emperiusm avatar May 07 '26 05:05 Emperiusm

⚠️ No Changeset found

Latest commit: dca353dd7abe461330f8abbb5cf40f9e9e217f90

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

changeset-bot[bot] avatar May 07 '26 05:05 changeset-bot[bot]

Review Change Stack No actionable comments were generated in the recent review. πŸŽ‰

ℹ️ Recent review info
βš™οΈ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 53fb58bd-8920-4104-ac21-bc720e677224

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 57b1be9bcb01c035bdc30aa1658db36197a409cb and dca353dd7abe461330f8abbb5cf40f9e9e217f90.

β›” Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
πŸ“’ Files selected for processing (2)
  • packages/s3-store/package.json
  • packages/s3-store/src/index.ts

Walkthrough

The S3 store's multipart upload concurrency control is refactored to replace @shopify/semaphore with async-mutex. The dependency is updated, the import is switched, and the uploadParts method is adapted to use the new library's callback-based release API instead of permit objects.

Changes

Semaphore library replacement

Layer / File(s) Summary
Dependency & Import Migration
packages/s3-store/package.json, packages/s3-store/src/index.ts
Dependency declaration replaced with async-mutex and import statement updated to use the new library instead of @shopify/semaphore.
Semaphore API Implementation
packages/s3-store/src/index.ts
uploadParts method refactored to track and invoke a releasePermit callback instead of storing and calling .release() on a Permit object; cleanup and error handlers adapted to use optional chaining with the release function.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • tus/tus-node-server#728: Modifies packages/s3-store multipart upload permit release logic; directly related refactoring of semaphore/concurrency handling.
πŸš₯ Pre-merge checks | βœ… 5
βœ… Passed checks (5 passed)
Check name Status Explanation
Title check βœ… Passed The title accurately summarizes the main change: replacing @shopify/semaphore with async-mutex in the s3-store package.
Description check βœ… Passed The description provides clear rationale (archived dependency), implementation details, API differences, and verification steps directly related to the changeset.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
πŸ§ͺ Generate unit tests (beta)
  • [ ] Create PR with unit tests

[!WARNING]

Review ran into problems

πŸ”₯ Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.

[!TIP]

πŸ’¬ Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire orgβ€”no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-inβ€”scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

πŸ‘‰ Get started


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.

coderabbitai[bot] avatar May 07 '26 05:05 coderabbitai[bot]

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedasync-mutex@​0.5.010010010080100

View full report

socket-security[bot] avatar May 07 '26 05:05 socket-security[bot]

Perhaps we should just copy the class from @shopify/semaphore, it's been working well for us, it's not a moving target the datastructure isn't going to change, and then we own it and reduce dependency problems and security.

Can you update?

Murderlon avatar May 09 '26 08:05 Murderlon