Commit 404453c
Fix a teardown race in HttpProxyStateTracker (#41097)
* Fix a teardown race in HttpProxyStateTracker
HttpProxyStateTracker::QueryProxySettingsAsync() published the WinHTTP
resolver/session handles and reset m_requestFinished only after calling
WinHttpGetProxySettingsEx(). Since that call can complete (or fail
synchronously) before returning, the destructor could run concurrently
with request setup: it could observe m_requestFinished still signaled
and tear down the queue and unregister the proxy-change notification
while a request was still starting up, or close handles before they
were fully published.
Fix this by:
- Adding a lock (m_requestLock) that serializes handle creation/teardown
between QueryProxySettingsAsync, RequestCompleted, and the destructor,
plus an m_stopping flag so no new request can start once teardown has
begun.
- Marking the request as in-flight (resetting m_requestFinished and
setting m_queryState) before calling WinHttpGetProxySettingsEx, so the
destructor cannot proceed past m_requestFinished.wait() while a
request is actually outstanding.
- Setting WINHTTP_OPTION_CONTEXT_VALUE on the resolver handle so that
WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING always carries a valid context,
including when WinHttpGetProxySettingsEx fails synchronously (which
produces no completion callback), so RequestClosed() reliably runs
and re-signals m_requestFinished instead of leaving it stuck.
- Reordering the constructor to register the proxy-change notification
before submitting the initial query, so a throw during registration
can't leave a queued task running against a partially-constructed
object.
Tested locally with repeated concurrent wsl -e / wsl --shutdown races
(including tight construct-then-shutdown loops) with no crashes or
hangs observed.
* fix formatting
---------
Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>1 parent 96b220c commit 404453c
2 files changed
Lines changed: 39 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
280 | | - | |
281 | | - | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
282 | 285 | | |
283 | 286 | | |
284 | 287 | | |
| |||
442 | 445 | | |
443 | 446 | | |
444 | 447 | | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
445 | 454 | | |
446 | 455 | | |
447 | 456 | | |
| |||
469 | 478 | | |
470 | 479 | | |
471 | 480 | | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
472 | 485 | | |
473 | 486 | | |
474 | 487 | | |
| |||
483 | 496 | | |
484 | 497 | | |
485 | 498 | | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
486 | 503 | | |
487 | 504 | | |
488 | | - | |
489 | | - | |
| 505 | + | |
490 | 506 | | |
491 | 507 | | |
492 | 508 | | |
| |||
496 | 512 | | |
497 | 513 | | |
498 | 514 | | |
499 | | - | |
500 | | - | |
501 | 515 | | |
502 | 516 | | |
503 | 517 | | |
| |||
514 | 528 | | |
515 | 529 | | |
516 | 530 | | |
517 | | - | |
518 | 531 | | |
| 532 | + | |
519 | 533 | | |
520 | 534 | | |
521 | 535 | | |
| |||
529 | 543 | | |
530 | 544 | | |
531 | 545 | | |
532 | | - | |
533 | | - | |
534 | | - | |
535 | | - | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
536 | 556 | | |
537 | 557 | | |
538 | 558 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
201 | 207 | | |
202 | 208 | | |
203 | 209 | | |
| |||
229 | 235 | | |
230 | 236 | | |
231 | 237 | | |
232 | | - | |
233 | | - | |
| 238 | + | |
| 239 | + | |
234 | 240 | | |
235 | 241 | | |
236 | 242 | | |
| |||
0 commit comments