Skip to content

Fix virtual-thread deadlocks during synchronous paging - #50918

Merged
Alan Zimmer (alzimmermsft) merged 4 commits into
mainfrom
vcolin7-identity-thread-deadlock
Oct 26, 2026
Merged

Alan Zimmer (alzimmermsft) merged 4 commits into
mainfrom
vcolin7-identity-thread-deadlock

Conversation

@vcolin7

@vcolin7 vcolin7 commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Description

Fixes synchronous paging holding an intrinsic monitor while Identity waits for MSAL. On Java 21, those callers can occupy all carrier threads and prevent the shared executor's token work from running.

Replaces the paging monitor with a private ReentrantLock, preserving the existing critical section and error handling. Adds isolated-JVM coverage with scarce carriers and tests for lock release after failure or interruption. Corrects Identity's executor and virtual-thread workaround documentation. Public APIs and default executor settings are unchanged.

Fixes #46231.

Validation

Before the fix, all eight new Java 21 low-carrier paging cases failed with timeouts. After the fix, the paging suites passed on Java 21 and 25 (132 cases each). Java 8 passed 124 cases and skipped the eight virtual-thread cases as expected.

Commands were run on Windows with JAVA_HOME and PATH set to the indicated JDK:

# JDK 21: passed package, selected tests, Revapi, SpotBugs, Checkstyle, and Spotless checks.
mvn --offline --batch-mode --no-transfer-progress -q -f sdk\core\azure-core\pom.xml clean package revapi:check spotbugs:check checkstyle:check spotless:check '-Dtest=PagedIterableConcurrencyTests,PagedIterableTest,PagedFluxTest' '-Dgpg.skip=true' '-Dspotbugs.skip=false'

# JDK 25: passed all 132 selected tests.
mvn --offline --batch-mode --no-transfer-progress -q -f sdk\core\azure-core\pom.xml test '-Dtest=PagedIterableConcurrencyTests,PagedIterableTest,PagedFluxTest' '-Dgpg.skip=true' '-Dspotbugs.skip=false'

# JDK 8: passed 124 tests; eight virtual-thread cases skipped.
mvn --offline --batch-mode --no-transfer-progress -q -f sdk\core\azure-core\pom.xml surefire:test '-Dtest=PagedIterableConcurrencyTests,PagedIterableTest,PagedFluxTest' '-Dgpg.skip=true' '-Dspotbugs.skip=false'

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Written with the help of Copilot

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused lock replacement preserves existing behavior, has targeted regression coverage, and has no identified blocking issues.

No open issues 🎉

What changed in this PR

Fixes synchronous paging deadlocks reported in #46231 by avoiding virtual-thread carrier pinning in Azure Core on Java 21.

Changes:

  • Replaces the paging monitor with a private ReentrantLock, preserving the critical section and error handling.
  • Adds isolated-JVM tests with limited carriers and lock-release tests for failure and interruption.
  • Corrects Identity executor guidance and documents the fix in Azure Core’s changelog.
File Description
sdk/​identity/​azure-identity/​TROUBLESHOOTING.md Clarifies the default executor and virtual-thread workarounds.
sdk/​core/​azure-core/​src/​test/​java/​com/​azure/​core/​http/​rest/​PagedIterableConcurrencyTests.java Adds carrier-starvation and exceptional lock-release coverage.
sdk/​core/​azure-core/​src/​main/​java/​com/​azure/​core/​util/​paging/​ContinuablePagedByIteratorBase.java Replaces intrinsic synchronization with a lock released in finally.
sdk/​core/​azure-core/​CHANGELOG.md Records the synchronous paging deadlock fix.

Review effort: Balanced

@github-project-automation github-project-automation Bot moved this from Untriaged to In Progress in Azure Identity SDK Improvements Oct 23, 2026
@alzimmermsft
Alan Zimmer (alzimmermsft) merged commit ea58590 into main Oct 26, 2026
41 checks passed
@alzimmermsft
Alan Zimmer (alzimmermsft) deleted the vcolin7-identity-thread-deadlock branch October 26, 2026 15:28
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Azure Identity SDK Improvements Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

[BUG] Deadlock when using DefaultAzureCredentials and virtual threads are available

4 participants