This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Commit 42b4772
authored
Fix ManagedWebSocket cancellation race condition (#27407)
When a cancelable cancellation token is passed to Receive/SendAsync, the code registers with the token to abort the web socket. The resulting exception is then translated into an OperationCanceledException if _abort is true. But this logic doesn't count on the possibility that the underlying Read/WriteAsync on the transport stream could actually throw a cancellation exception. If it does, there's a race condition as to whether the web socket's abort flag will be set in time; if it is, we wrap the cancellation exception in another cancellation exception, and if it's not, we treat it as a non-cancellation exception. This commit fixes that, by explicitly allowing OperationCanceledExceptions to proceed uninterrupted. This should fix the ReceiveAsync_AfterCancellationDoReceiveAsync_ThrowsWebSocketException test, which recently started failing sporadically, I believe because we improved the cancellation support in SocketsHttpHandler, on top of which ClientWebSocket now sits.1 parent 517238c commit 42b4772
1 file changed
+6
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
415 | 415 | | |
416 | 416 | | |
417 | 417 | | |
418 | | - | |
419 | | - | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
420 | 421 | | |
421 | 422 | | |
422 | 423 | | |
| |||
437 | 438 | | |
438 | 439 | | |
439 | 440 | | |
440 | | - | |
| 441 | + | |
441 | 442 | | |
442 | 443 | | |
443 | 444 | | |
| |||
457 | 458 | | |
458 | 459 | | |
459 | 460 | | |
460 | | - | |
| 461 | + | |
461 | 462 | | |
462 | 463 | | |
463 | 464 | | |
| |||
739 | 740 | | |
740 | 741 | | |
741 | 742 | | |
742 | | - | |
| 743 | + | |
743 | 744 | | |
744 | 745 | | |
745 | 746 | | |
| |||
0 commit comments