Skip to content

Commit 02898e7

Browse files
jeet1995Copilot
andcommitted
Fix JVM <clinit> deadlock in Cosmos SDK accessor initialization
Replace broad initializeAllAccessors() fallback calls in each getXxxAccessor() method with targeted Class.forName() that loads only the specific class registering that accessor. This eliminates the circular class initialization dependency chain that caused permanent JVM-level deadlocks when multiple threads concurrently triggered Cosmos SDK class loading for the first time. Root cause: When any getXxxAccessor() found its accessor unset, it called initializeAllAccessors() which eagerly loaded 40+ classes via ModelBridgeInternal, UtilBridgeInternal, and BridgeInternal. If two threads entered different <clinit> methods simultaneously, the JVM class initialization monitors created an AB/BA deadlock that was permanent and unrecoverable. Fix: Each of the 35 getXxxAccessor() methods now calls ensureClassInitialized() with just the fully-qualified name of the class that registers that specific accessor. This dramatically narrows the class loading scope per accessor call, making circular dependencies practically impossible. The public initializeAllAccessors() method is preserved for explicit eager bootstrap use cases (e.g., Kafka connector, Spring @PostConstruct workaround). Fixes: #48622 Fixes: #48585 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3a6b4a5 commit 02898e7

2 files changed

Lines changed: 57 additions & 38 deletions

File tree

sdk/cosmos/azure-cosmos/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#### Bugs Fixed
1010
Fixing an NPE caused due to boxed Boolean conversion. - See [PR 48656](https://github.com/Azure/azure-sdk-for-java/pull/48656/)
11+
* Fixed JVM-level `<clinit>` deadlock caused by `ImplementationBridgeHelpers.initializeAllAccessors()` eagerly loading all Cosmos SDK classes during concurrent class initialization. Each accessor getter now performs targeted class loading (via `Class.forName`) of only the specific class it needs, eliminating the circular initialization dependency chain that caused permanent thread deadlocks in multi-threaded applications and CI environments. - See [PR XXXX](https://github.com/Azure/azure-sdk-for-java/pull/XXXX)
1112

1213
#### Other Changes
1314

0 commit comments

Comments
 (0)