fix: remove PgSemaphore to fix the payment deadlock#2720
Conversation
📝 WalkthroughWalkthroughRemoves the distributed PostgreSQL semaphore implementation and decorator usage, deletes related tests and provider initialization, replaces one distributed semaphore with an in-process Sema(1), and removes semaphore-related test setup and a concurrency test. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Comment |
fcbceaf to
d306817
Compare
| return { data: [] }; | ||
| } | ||
|
|
||
| @Semaphore() |
There was a problem hiding this comment.
this is logically redundant. We have it properly implemented on the frontend and if implemented via api - it would not do a double call. in the worst case we could do a refund
|
|
||
| @Semaphore() | ||
| @Protected([{ action: "create", subject: "StripePayment" }]) | ||
| async applyCoupon( |
There was a problem hiding this comment.
apply coupon is already idempotent op in stripe.
| this.logger.info({ event: "WALLET_BALANCE_REDUCED", userId, amountUsd, previousLimit: currentLimit, nextLimit }); | ||
| } | ||
|
|
||
| @Semaphore() |
There was a problem hiding this comment.
user wallet has a unique index on userId so sema is redundant here
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@apps/api/src/billing/lib/batch-signing-client/batch-signing-client.service.ts`:
- Around line 144-146: hasPendingTransactions currently returns
this.sema.nrWaiting() > 0 which misses in-flight batches; introduce an
activeBatches counter (e.g., this.activeBatches = 0) and update
hasPendingTransactions to check both this.sema.nrWaiting() and
this.activeBatches; increment activeBatches immediately after successfully
acquiring the semaphore in the method that starts a batch (the same place the
tx-signer increments) and decrement it in that method's finally block so
activeBatches accurately reflects in-flight operations and prevents premature
cleanup.
apps/api/src/billing/lib/batch-signing-client/batch-signing-client.service.ts
Show resolved
Hide resolved
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project status has failed because the head coverage (75.01%) is below the target coverage (78.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #2720 +/- ##
==========================================
- Coverage 52.24% 51.35% -0.89%
==========================================
Files 1057 1019 -38
Lines 28032 27136 -896
Branches 6357 6255 -102
==========================================
- Hits 14644 13937 -707
+ Misses 12953 12774 -179
+ Partials 435 425 -10
*This pull request uses carry forward flags. Click here to find out more.
🚀 New features to boost your workflow:
|
PgSemaphore is no longer needed in the console API. All operations using it are either logically safe without locking or already idempotent. BatchSigningClientService, the only remaining consumer, is only used for testing or in single instance mode, so a simple in-process Sema(1) is sufficient.
d306817 to
448b024
Compare
PgSemaphore is no longer needed in the console API. All operations using it are either logically safe without locking or already idempotent. BatchSigningClientService, the only remaining consumer, is only used for testing or in single instance mode, so a simple in-process Sema(1) is sufficient.
Summary by CodeRabbit