-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Call StopAsync before disposing #6189
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
Conversation
Why does StopAsync go async? |
@pakrym waiting for graceful shutdown. It waits 5 seconds by default for all connections to close https://github.com/aspnet/AspNetCore/blob/master/src/Servers/Kestrel/Core/src/KestrelServer.cs#L182-L205. In Kestrel, that means canceling input pipes and waiting for the task representing that connection to complete for all connections (usually one or 2 in tests). |
Aren't we closing most of the connections before disposing the server? |
This looks good as temporary solution before we get |
Those get queued, so dispose queues shutdown to the thread pool for connections then returns. Then server shutdown occurs on the test thread itself while it waits for those callbacks to be executed while running on the thread pool. Even though it looks sequential, connection close and server shutdown happen in parallel.
Yea, we need to switch over to that as soon as it becomes available. I'll file an issue. This change is too cumbersome but should make the tests generally more reliable. |
@davidfowl Is there a reason why you call |
Wasn't aware of it but I will look at doing this in a few other places. I'm assuming this is for class level stuff. Most of these tests are creating and disposing things within each test and IAsyncDisposable fits that more naturally. |
Yes, that's on Class Level. If you're still looking for starvation issues, |
@davidfowl Can we backport this to 2.2? Getting failures there https://dev.azure.com/dnceng/public/_build/results?buildId=72570 |
@BrennanConroy sure 😄 Are you going to do it? |
Nope, looks like it might not even have fixed the issue? https://github.com/aspnet/AspNetCore-Internal/issues/1370#issuecomment-451596960 |
It happens alot less, there might be other reasons for starvation but @JunTaoLuo is trying to collect a dump |
Let's just back port the fix. If the test fails again, we'll be able to collect dumps. The test hasn't failed in a long time so @davidfowl 's fix certainly improved reliability. |
I'm not planning to do this so I suggest we file an issue, assign it to somebody so it doesn't get lost |
@BrennanConroy seemed passionate so I volunteered him to backport. |
Turns out #6127 is caused by thread pool starvation that happens via calls to
TestServer.Dispose
, see #6127 (comment). I did this for the InMemory.FunctionalTests but there are likely other tests that need to be fixed. Ideally we would support IAsyncDisposable and would do await using instead of this once we get those features.Without IAsyncDisposable, test failures could still cause this issue.