Repository navigation
fix: EXPOSED-1097 Make JDBC transaction context registry thread-safe - #2950
Open
Michael Hancock (mikehancock) wants to merge 2 commits into
Open
Michael Hancock (mikehancock) wants to merge 2 commits into
Michael Hancock (mikehancock) wants to merge 2 commits into
Conversation
This branch has not been deployed
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
Summary of the change:
TransactionManager.contextKeysis a plainLinkedHashMapread without synchronization while databases are registered and unregistered concurrently. This replaces it with aConcurrentHashMap.Detailed description:
registerManagerandcloseAndUnregisterare@Synchronized, butgetContextKeyreadscontextKeyswithout any lock. A read that overlaps a resize can return null for a manager that is still registered, sogetContextKeythrowsIllegalStateException: No context key found for transaction manager .... We hit this as intermittent HTTP 500s in an integration test suite with pooled test applications that each register their ownDatabase. Related to the same class of problem fixed forIdentifierManagerApiin fix: fix thread-safety of IdentifierManagerApi identifier caches (#1704) #2783 (EXPOSED-1014).contextKeysin the JDBCTransactionManagercompanion is now aConcurrentHashMap. No public API changes.IdentifiersCachein fix: fix thread-safety of IdentifierManagerApi identifier caches (#1704) #2783,contextKeyshas no eviction policy, soConcurrentHashMaploses nothing. The@Synchronizedwriters still work, and reads become safe without extra locking.Added
testContextKeysRemainAvailableDuringConcurrentDatabaseRegistrationtoCustomTransactionManagerTest. It reads existing managers' keys from 4 threads while registering many more mock databases (no SQL connections are opened), then unregisters them. It fails on unmodifiedmainwith the missing-context-key exception and passes with the fix.Type of Change
Updates/remove existing public API methods:
Affected databases:
Validation
main, passes with the fix.apiCheckanddetektpass for both affected modules.The R2DBC
TransactionManageruses the same pattern (plainmutableMapOf, unsynchronized read ingetContextKey). This PR is limited to JDBC; I'm happy to apply the same change to R2DBC here or in a follow-up, whichever you prefer.Checklist
Related Issues
EXPOSED-1097
Related: EXPOSED-1014 (#2783)