Extract concurrency utilities, add multithreaded tests, fix two races#30
Merged
Merged
Conversation
Pull the hand-rolled "complicated combinations" of concurrency primitives
that were duplicated across modules into small, business-logic-free,
thoroughly multithreaded-tested utilities in a new common.concurrent
package (and a CoordinationCas helper in the coordination module), then
swap the call sites onto them. Along the way, fix two latent concurrency
defects surfaced by the audit.
New utilities (each with race-injecting concurrent tests):
- BoundedLruCache: thread-safe access-ordered LRU (was an inline
synchronizedMap(LinkedHashMap{removeEldestEntry}) in BoxEngine).
- TtlCache: read-through TTL cache with loaders run outside the locks
(was a ConcurrentHashMap<K,(value,expiresAt)> copy in BoxAclStore,
S3AccessControl, and ClusterRouter).
- KeyedSlidingWindow: per-key bounded sliding window (was a
ConcurrentHashMap<K,ArrayDeque> guarded by synchronized(deque) in
MetricsScraper).
- PeriodicGate: run-at-most-once-per-interval throttle via a volatile
deadline + double-checked lock (was inline in FileCredentialStore).
- CoordinationCas: optimistic upsert/delete-with-bounded-retry over
CoordinationService (was duplicated in BoxAclStore and CandyboxNode).
Defect fixes (each with a failing-first regression test):
- ClusterRouter opened connections inside ConcurrentHashMap.computeIfAbsent,
running blocking connect() under a bin lock (a documented anti-pattern).
Connect outside the map locks now; a lost race closes the surplus.
- BoxEngine checked the idempotency cache only outside the write lock, so
two concurrent retries of the same token could both apply the mutation.
Re-check under the lock so the second caller returns the cached result.
All affected module unit suites pass (583 tests, 0 failures); both
regression tests were confirmed to fail when the fix is reverted.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CdFZHjRQrHzD6FgbDgzh1B
✅ S3 compatibility gate passed
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #30 +/- ##
=========================================
Coverage 83.82% 83.82%
+ Complexity 677 674 -3
=========================================
Files 162 167 +5
Lines 9284 9369 +85
Branches 1397 1404 +7
=========================================
+ Hits 7782 7854 +72
- Misses 998 1012 +14
+ Partials 504 503 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Pull the hand-rolled "complicated combinations" of concurrency primitives
that were duplicated across modules into small, business-logic-free,
thoroughly multithreaded-tested utilities in a new common.concurrent
package (and a CoordinationCas helper in the coordination module), then
swap the call sites onto them. Along the way, fix two latent concurrency
defects surfaced by the audit.
New utilities (each with race-injecting concurrent tests):
synchronizedMap(LinkedHashMap{removeEldestEntry}) in BoxEngine).
(was a ConcurrentHashMap<K,(value,expiresAt)> copy in BoxAclStore,
S3AccessControl, and ClusterRouter).
ConcurrentHashMap<K,ArrayDeque> guarded by synchronized(deque) in
MetricsScraper).
deadline + double-checked lock (was inline in FileCredentialStore).
CoordinationService (was duplicated in BoxAclStore and CandyboxNode).
Defect fixes (each with a failing-first regression test):
running blocking connect() under a bin lock (a documented anti-pattern).
Connect outside the map locks now; a lost race closes the surplus.
two concurrent retries of the same token could both apply the mutation.
Re-check under the lock so the second caller returns the cached result.
All affected module unit suites pass (583 tests, 0 failures); both
regression tests were confirmed to fail when the fix is reverted.
Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01CdFZHjRQrHzD6FgbDgzh1B