Repository navigation
Conversation
…tion fails TokenMap.updateConfigByJson released its semaphore only on success, so a single corrupted config or throwing callback blocked every later update forever. It now runs through Semaphore.use, which releases on every path. CustomQueryRunner kept its mutex when startTransaction or rollbackTransaction failed, blocking every later transaction on the runner. Both now release on failure. Commit still releases only on success on purpose: a failed commit leaves the transaction active, and the caller's rollback is what ends it and releases the mutex.
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
Two items from rosen-bridge/guard-service#28 ("a lock that is not released on every path") live in this repo. Both turn a single transient failure into a permanent hang:
TokenMap.updateConfigByJson(@rosen-bridge/tokens) released its semaphore only on success. After one corrupted config (CorruptedConfigError) or one throwing callback, every laterupdateConfigByJsonon the sameTokenMapwaits forever.CustomQueryRunner(@rosen-bridge/extended-typeorm) kept its mutex whenrollbackTransactionrejected — and also whenstartTransactionfailed after acquiring it. Since the driver hands out a single shared runner, one failure blocked every later transaction on that data source.Fix
TokenMap: run the update through the semaphore's ownuse()helper, which releases on both success and error. No behavior change otherwise — config is still only assigned after full validation, and callbacks still run inside the lock.CustomQueryRunner.startTransaction: release the just-acquired mutex if the transaction never started (nothing else can release it), and only store the releaser on success.CustomQueryRunner.rollbackTransaction: release in afinally— the transaction is over either way, so keeping the mutex only bricks the runner.CustomQueryRunner.commitTransactionis deliberately unchanged: when a commit fails, the transaction is still active and the caller's rollback (this is exactly what TypeORM'sEntityManager.transactiondoes) is what ends it and releases the mutex. Releasing incommitwould make that rollback throwCannot rollback transaction before starting itand leave the transaction open. I also initialized thereleaseMutexfield tonullto match its declared type — it wasundefineduntil the first transaction.Tests
Tests first — each new test fails on the current code and passes with the fix:
COMMITbehind the runner's back) both leavereleaseMutex === nulland the mutex unlocked, and a valid transaction still starts and commits afterwards. Package suite 4/4.Dependents re-checked: root
npm run buildclean,extended-tokens12/12,rosen-extractor228/228,tx-pot50/50.tsc --noEmitclean for both packages; eslint/prettier clean. Changeset included (patch for both packages).The remaining items from guard-service#28 live in scanner (
abstractErgoExtractor.unhook) and sign-protocols (TssSigner) — not covered here.