Commit b53d87e
Fix ABBA deadlock between AzureActiveDirectory and AzureActiveDirectoryAuthority class monitors, Fixes AB#3578299 (#3082)
## Summary
Fixes an ABBA deadlock between `AzureActiveDirectory.class` and
`AzureActiveDirectoryAuthority.class` monitors, discovered during ANR
investigation on Microsoft Authenticator (Broker v16.0.0). Under high
concurrency (multiple apps calling into Broker simultaneously), two
threads could deadlock:
- **Path A** (`isKnownAuthority`): `sLock` →
`authority.getAuthorityURL()` → `AzureActiveDirectoryAuthority.class` →
`AzureActiveDirectory.class`
- **Path B** (`ensureCloudDiscoveryForAuthority`):
`AzureActiveDirectory.class` → `authority.getAuthorityURL()` →
`AzureActiveDirectoryAuthority.class`
## Changes
### Source (3 files)
**Authority.java**
- Extract `authority.getAuthorityURL()` outside `synchronized(sLock)` in
`isKnownAuthority()`
- Add null check for `authorityUrl`
- Improve error handling in `getKnownAuthorityResult()`: propagate
original discovery exception error code instead of replacing with
`UNKNOWN_AUTHORITY`
- Make `KnownAuthorityResult` fields `final`
**AzureActiveDirectory.java**
- Remove `synchronized` from read-only `ConcurrentHashMap` methods:
`hasCloudHost`, `getAzureActiveDirectoryCloud`,
`getAzureActiveDirectoryCloudFromHostName`, `isValidCloudHost`
- Extract `authority.getAuthorityURL()` outside synchronized scope in
`ensureCloudDiscoveryForAuthority(Authority)`
**AzureActiveDirectoryAuthority.java**
- Remove `synchronized` from `private static
getAzureActiveDirectoryCloud()`
### Tests (2 files)
**AzureActiveDirectoryTest.kt** — 5 concurrency regression tests:
1. ABBA deadlock between `isKnownAuthority` and `ensureCloudDiscovery`
2. Concurrent reads do not block (ConcurrentHashMap safety)
3. Concurrent `getAuthorityURL()` calls
4. Concurrent reader/writer scenarios
5. High-concurrency stress test with multiple authorities
**AuthorityKnownAuthorityTest.kt** — expanded:
- Sovereign cloud recognition (Bleu, Delos, GovSG)
- Null authority / null authorityUrl handling
- Error code propagation (IO_ERROR, MALFORMED_URL, UNKNOWN_AUTHORITY)
- Developer-configured authority with discovery failure
- Pre-seeded metadata fallback
## Linked Work Items
[AB#3578299](https://identitydivision.visualstudio.com/fac9d424-53d2-45c0-91b5-ef6ba7a6bf26/_workitems/edit/3578299)
---------
Co-authored-by: Mohit <mchand@microsoft.com>
Co-authored-by: Dome Pongmongkol <19558668+rpdome@users.noreply.github.com>1 parent d87bc2e commit b53d87e
File tree
6 files changed
+526
-70
lines changed- common4j/src
- main/com/microsoft/identity/common/java
- authorities
- providers/microsoft/azureactivedirectory
- test/com/microsoft/identity/common/java
- authorities
- providers/microsoft/azureactivedirectory
6 files changed
+526
-70
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
Lines changed: 49 additions & 36 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
321 | | - | |
322 | | - | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
323 | 333 | | |
324 | 334 | | |
325 | 335 | | |
326 | 336 | | |
327 | 337 | | |
328 | | - | |
| 338 | + | |
329 | 339 | | |
330 | 340 | | |
331 | 341 | | |
332 | 342 | | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
337 | 354 | | |
338 | 355 | | |
339 | 356 | | |
340 | | - | |
| 357 | + | |
341 | 358 | | |
342 | 359 | | |
343 | 360 | | |
344 | | - | |
345 | 361 | | |
346 | 362 | | |
347 | 363 | | |
348 | | - | |
349 | | - | |
| 364 | + | |
350 | 365 | | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
| 366 | + | |
355 | 367 | | |
356 | 368 | | |
357 | 369 | | |
| |||
360 | 372 | | |
361 | 373 | | |
362 | 374 | | |
363 | | - | |
| 375 | + | |
364 | 376 | | |
365 | 377 | | |
366 | 378 | | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
376 | 383 | | |
377 | 384 | | |
378 | 385 | | |
| |||
383 | 390 | | |
384 | 391 | | |
385 | 392 | | |
386 | | - | |
387 | | - | |
388 | 393 | | |
| 394 | + | |
389 | 395 | | |
390 | 396 | | |
391 | 397 | | |
392 | 398 | | |
393 | 399 | | |
394 | 400 | | |
395 | 401 | | |
| 402 | + | |
396 | 403 | | |
397 | 404 | | |
398 | 405 | | |
399 | 406 | | |
400 | 407 | | |
401 | | - | |
402 | | - | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
403 | 420 | | |
404 | 421 | | |
405 | 422 | | |
406 | | - | |
407 | | - | |
408 | | - | |
| 423 | + | |
409 | 424 | | |
410 | | - | |
411 | | - | |
412 | 425 | | |
413 | 426 | | |
414 | 427 | | |
415 | | - | |
416 | | - | |
| 428 | + | |
| 429 | + | |
417 | 430 | | |
418 | 431 | | |
419 | 432 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
178 | | - | |
| 178 | + | |
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
| |||
Lines changed: 15 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | | - | |
| 167 | + | |
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
171 | | - | |
172 | | - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
173 | 174 | | |
174 | 175 | | |
175 | 176 | | |
| |||
191 | 192 | | |
192 | 193 | | |
193 | 194 | | |
194 | | - | |
| 195 | + | |
195 | 196 | | |
196 | 197 | | |
197 | 198 | | |
198 | 199 | | |
199 | 200 | | |
200 | 201 | | |
201 | 202 | | |
202 | | - | |
| 203 | + | |
203 | 204 | | |
204 | 205 | | |
205 | 206 | | |
| |||
368 | 369 | | |
369 | 370 | | |
370 | 371 | | |
371 | | - | |
| 372 | + | |
372 | 373 | | |
373 | | - | |
374 | | - | |
375 | | - | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
376 | 382 | | |
377 | 383 | | |
378 | 384 | | |
| |||
0 commit comments