Skip to content

fix: make JDBC transaction context registry thread-safe - #2950

Open
Michael Hancock (mikehancock) wants to merge 2 commits into
JetBrains:mainfrom
mikehancock:codex/fix-transaction-context-registry-race
Open

Michael Hancock (mikehancock) wants to merge 2 commits into
JetBrains:mainfrom
mikehancock:codex/fix-transaction-context-registry-race

Conversation

@mikehancock

Copy link
Copy Markdown

Summary

Concurrent database registration can make getContextKey() throw IllegalStateException: No context key found for transaction manager for a manager that remains registered. contextKeys is a mutable map: registration and removal synchronize writes, but readers access it without synchronization while registrations can resize its backing table.

Use ConcurrentHashMap for the JDBC context-key registry. Add a regression that reads existing managers' keys while registering other databases, then unregisters the test databases. No SQL connections are opened and no public API changes are required.

The regression fails on unmodified main with the missing-context-key exception and passes with this fix. H2 transaction/coroutine coverage: 99 passed, 19 skipped. JDBC API compatibility and Detekt checks for both affected modules pass.

This branch has not been deployed

No deployments
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