-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Fix Socket test failure ClosedDuringOperation_Throws_ObjectDisposedExceptionOrSocketException #47575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Socket test failure ClosedDuringOperation_Throws_ObjectDisposedExceptionOrSocketException #47575
Conversation
|
Tagging subscribers to this area: @dotnet/ncl Issue DetailsFixes #47561. There is a timing race in the test. In sync case Dispose may happen before the operation is started. (Thread pool starvation defers
|
|
Test failure is #43928. |
|
|
||
| Task receiveTask = ReceiveMessageFromAsync(socket, new byte[1], GetGetDummyTestEndpoint()); | ||
| await Task.Delay(msDelay); | ||
| msDelay *= 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the msDelay chages hare. I don't see it used laster. Also the seems generally problematic as the time needed can vary greatly across platforms. Would it work if we simply accept either exception if we feel that should be expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see it used later.
The test is being retried 10 times in the sync case, doubling the delay time on each failure:
| await RetryHelper.ExecuteAsync(() => RunTestAsync(), maxAttempts: 10, retryWhen: e => e is XunitException); |
the time needed can vary greatly across platforms
The retry mechanism is here to address this. Most of the times the test will succeed within the 100ms delay. On slow platforms / high CI load, first attempts will fail with an ObjectDisposedException, but eventually one of the subsequent retries will observe a SocketException
I adapted this practice from an existing test introduced in dotnet/corefx#38804:
runtime/src/libraries/System.Net.Sockets/tests/FunctionalTests/SendReceive/SendReceive.cs
Lines 938 to 943 in 7adf3db
| // We try this a couple of times to deal with a timing race: if the Dispose happens | |
| // before the operation is started, the peer won't see a ConnectionReset SocketException and we won't | |
| // see a SocketException either. | |
| int msDelay = 100; | |
| await RetryHelper.ExecuteAsync(async () => | |
| { |
|
I hate that the test param is named |
Fixes #47561.
#47229 introduced a test with a timing race. In sync case Dispose may happen before the operation is started. (Thread pool starvation defers
Task.Run()stuff inSocketTestHelper?)@geoffkizer @wfurt PTAL