Skip to content

fix: cachedFetcher.update() no longer blocks token reads during DB refresh#1535

Open
NETIZEN-11 wants to merge 1 commit intohyperledger-labs:mainfrom
NETIZEN-11:fix/sherdlock-update-blocked-readers
Open

fix: cachedFetcher.update() no longer blocks token reads during DB refresh#1535
NETIZEN-11 wants to merge 1 commit intohyperledger-labs:mainfrom
NETIZEN-11:fix/sherdlock-update-blocked-readers

Conversation

@NETIZEN-11
Copy link
Copy Markdown

What was fixed

The cachedFetcher.update() function in token/services/selector/sherdlock/fetcher.go was holding a write lock for the entire duration of the database query. This meant whenever the cache needed to refresh (e.g., on a slow DB), all token read operations would block waiting for the lock.

How it was fixed

  • Released the lock before executing the DB query
  • Added a staleness re-check after the DB call completes, to avoid overwriting a cache that another goroutine may have already refreshed
  • The cache update still happens atomically once the lock is re-acquired

Tests added

  • TestCachedFetcher_UpdateDoesNotBlockReaders: verifies that concurrent readers can still acquire the lock while update() is waiting on the database
  • TestCachedFetcher_UpdateReacquiresLockAfterDB: verifies the cache is correctly updated after the lock is re-acquired
go test -v -run "TestCachedFetcher_UpdateDoesNotBlockReaders|TestCachedFetcher_UpdateReacquiresLockAfterDB" ./token/services/selector/sherdlock/...
image

Signed-off-by: Nitesh <nitesh@example.com>
@NETIZEN-11 NETIZEN-11 force-pushed the fix/sherdlock-update-blocked-readers branch from c05df30 to 3b791af Compare April 12, 2026 19:22
@NETIZEN-11
Copy link
Copy Markdown
Author

@adecaro Would love a review on this. Thanks!

@adecaro
Copy link
Copy Markdown
Contributor

adecaro commented Apr 13, 2026

Hi @NETIZEN-11 , thanks for submitting this 🙏
I'll review ASAP but, please, open a Github Issue related to this.

Thanks much 🙏

@adecaro
Copy link
Copy Markdown
Contributor

adecaro commented Apr 13, 2026

@NETIZEN-11 , please, run make lint-auto-fix. It should solve the current lint errors 🙏

@adecaro adecaro self-assigned this Apr 13, 2026
@adecaro adecaro self-requested a review April 13, 2026 05:41
@adecaro adecaro added this to the Q2/26 milestone Apr 13, 2026
@AkramBitar AkramBitar added the enhancement New feature or request label Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request token-selector

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants