Skip to content

fix(dependency-injection): fix concurrency races in bindSet and auto-singleton registration#88

Merged
deer merged 1 commit into
mainfrom
di_concurrency
Jun 3, 2026
Merged

fix(dependency-injection): fix concurrency races in bindSet and auto-singleton registration#88
deer merged 1 commit into
mainfrom
di_concurrency

Conversation

@deer

@deer deer commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator
  • bindSet had a TOCTOU race between containsKey and computeIfAbsent on the ConcurrentHashMap of multibinding entries. Replaced with a single atomic compute call using an AtomicBoolean to track whether the entry was newly created, ensuring contributeBinding is called exactly once regardless of thread interleaving.
  • Concurrent first-touch creation of an unbound @Singleton type could cause the losing thread to receive an unexpected BindingAlreadyExistsException from addBinding. The auto-registration path in getValue now catches BindingAlreadyExistsException and silently defers to the binding registered by the winning thread.

@deer deer merged commit 5c8121e into main Jun 3, 2026
1 check passed
@deer deer deleted the di_concurrency branch June 3, 2026 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant