Conversation
getGlobal and getForWallet fired an unawaited remove keyed on _id when they found an expired entry. setGlobal's upsert refreshes the same document in place, so that delete could land after a concurrent (or the same request's own) refresh and silently discard the new entry, leaving hot keys perpetually cache-missing around every expiry. Await the delete and match on the stale created stamp so it can only ever remove the version that was actually observed expired.
kajoseph
reviewed
Sep 18, 2026
kajoseph
left a comment
Collaborator
There was a problem hiding this comment.
Nice catch! While we're at it, might as well change the deprecated .remove to .deleteOne
| } else { | ||
| // cache miss | ||
| this.collection.remove({ _id: found._id }); | ||
| // cache miss - only delete the version seen expiring; a refresh reuses the _id |
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.
Description
CacheStorage.getGlobalandgetForWalletfire an unawaitedremovekeyed on_idwhen they read an expired entry.setGlobal's upsert refreshes the same document in place, so a delete that lands late removes the entry that was just written. Around each expiry a hot key can end up missing on every request, and each miss re-runs the underlying lookup (RPC fee estimates today, plus any othergetGlobalOrRefreshconsumer). Surfaced while reviewing cache usage in the wallet stats work (#4250).Changelog
createdstamp, so the delete only removes the version that was actually read as expired. A concurrently refreshed entry keeps its_idbut gets a newcreated, and the stale delete no-ops against it.Testing Notes
Covered by the new cases in the Cache Model integration suite. Fresh entries and normal expiry behave the same as before.
Checklist
BWCif modifying the bitcore-wallet-client package,CLIif modifying the bitcore-cli package, etc.)