fix(maintenance-pool): wrap deposit() in dataSource.transaction() to resolve PessimisticLockTransactionRequiredError (#457) - #478
Open
PINYOPATTANAWASANPORN wants to merge 1 commit into
Conversation
…rgeFi#457) SELECT FOR UPDATE (pessimistic_write) on a plain injected Repository throws PessimisticLockTransactionRequiredError because TypeORM refuses pessimistic locks without an active transaction. Wrapping deposit() in dataSource.transaction() provides an active QueryRunner before the locked query executes. All operations inside the transaction now use the EntityManager API (manager.createQueryBuilder, manager.update, manager.increment, manager.findOneByOrFail) to share the same connection and transaction. Tests added: 5 unit tests verifying transaction wrapping, SELECT FOR UPDATE lock, NotFoundException, BadRequestException, and escrow creation paths.
|
@PINYOPATTANAWASANPORN is attempting to deploy a commit to the chonilius' projects Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
Wraps the entire
MaintenancePoolService.deposit()indataSource.transaction()so theSELECT … FOR UPDATEpessimistic lock executes inside an active transaction.Root Cause (#457)
The
#275fix addedsetLock('pessimistic_write')to the pool query insidedeposit(), but nothing wraps the method in a transaction. TypeORM'sSelectQueryBuilder.executeEntitiesAndRawResultsguards:Every
POST /maintenance-pool/:id/deposittherefore 500s before reaching any business logic, making the endpoint completely non-functional.Fix
All subsequent
poolRepo.update/poolRepo.increment/findOnecalls inside the method are replaced withmanager.*equivalents so all operations share the same connection and transaction boundary.Verification & Testing
5 unit tests added to
maintenance-pool.service.spec.ts:wraps deposit() in dataSource.transaction()—dataSource.transactioncalled onceissues SELECT … FOR UPDATE (pessimistic_write) on the manager QueryBuilder—setLock('pessimistic_write')assertedthrows NotFoundException when pool is not found inside the transactionthrows BadRequestException for a non-ACTIVE poolcalls escrowService.fund on first deposit (escrowId is null)Impact & Compatibility
deposit()public signature is unchanged.DataSourceis injected via@InjectDataSource(), already available in the NestJS DI container.Closes #457