Skip to content

QUIC: QuicStream.WaitForWriteCompletionAsync sometimes doesn't complete #71927

Open

Description

@JamesNK

Description

I've noticed Kestrel sometimes throws an error when handling a gRPC request. See dotnet/aspnetcore#42289

tldr; the client sent a gRPC request, the server processed it and sent a response, but aborted the connection because the request is hung on WaitForWriteCompletionAsync, and thought the request was still in-progress and exceeded the timeout to drain the request.

I investigated what is going on and it appears that most of the time in my scenario QuicStream.WaitForWriteCompletionAsync never returns. It appears to work reliably if there is a breakpoint before awaiting on a task, but not if there is a breakpoint after awaiting the task.

Reproduction Steps

  1. git clone https://github.com/jamesnk/grpc-dotnet
  2. git checkout jamesnk/net7
  3. dotnet run -c Release --project .\perf\benchmarkapps\GrpcAspNetCoreServer\ -- --LogLevel Trace --protocol h3
  4. dotnet run -c Release --project .\perf\benchmarkapps\GrpcClient\ -- -u https://localhost:5000 -c 1 --streams 1 -s unary -p h3 --grpcClientType grpcnetclient --callCount 1

Expected behavior

Client and server gracefully complete request.

Actual behavior

Half the time the QuicStream.WaitForWriteCompletionAsync task doesn't complete. The server aborts the request and the connection because they're unhealthy.

Logs of success and failure are below.

Success logs:

23.0973 dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Quic[2]
      Stream id "0HMJ31P1V8BHG:00000002" type Unidirectional accepted.
23.0974 trce: Microsoft.AspNetCore.Server.Kestrel.Http3[46]
      Connection id "0HMJ31P1V8BHG" received SETTINGS frame for stream ID 2 with length 5.
23.1109 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#66993893,NativeCallback,[conn][0x29C45A0F6F0] Connection received event PEER_STREAM_STARTED ->
23.1109 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : SafeMsQuicStreamHandle#14836038,.ctor,MsQuicSafeHandle created ->
23.1109 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#29809623,.ctor,[strm][0x29C459C94D0] Inbound bidirectional stream created in connection [conn][0x29C45A0F6F0] with StreamId 0. ->
23.1109 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#29809623,NativeCallback,[strm][0x29C459C94D0] Stream received event RECEIVE ->
23.1109 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#29809623,HandleEventReceive,[strm][0x29C459C94D0] Stream received 256 bytes ->
23.1110 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#29809623,ReadAsync,[strm][0x29C459C94D0] Stream reading into Memory of '4096' bytes. ->
23.1110 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#29809623,ReadAsync,[strm][0x29C459C94D0] Stream reading into Memory of '4096' bytes. ->
23.1114 dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Quic[2]
      Stream id "0HMJ31P1V8BHG:00000000" type Bidirectional accepted.
23.1117 trce: Microsoft.AspNetCore.Server.Kestrel.Http3[46]
      Connection id "0HMJ31P1V8BHG" received HEADERS frame for stream ID 0 with length 251.
23.1117 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#29809623,NativeCallback,[strm][0x29C459C94D0] Stream received event RECEIVE ->
23.1117 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#29809623,HandleEventReceive,[strm][0x29C459C94D0] Stream received 7 bytes ->
23.1119 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#29809623,ReadAsync,[strm][0x29C459C94D0] Stream reading into Memory of '4096' bytes. ->
23.1119 trce: Microsoft.AspNetCore.Server.Kestrel.Http3[46]
      Connection id "0HMJ31P1V8BHG" received DATA frame for stream ID 0 with length 7.
23.1121 info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/3 POST https://localhost:5000/grpc.testing.BenchmarkService/UnaryCall application/grpc -
23.1121 trce: Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware[2]
      All hosts are allowed.
23.1121 dbug: Microsoft.AspNetCore.Routing.Matching.DfaMatcher[1001]
      1 candidate(s) found for the request path '/grpc.testing.BenchmarkService/UnaryCall'
23.1121 dbug: Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware[1]
      Request matched endpoint 'gRPC - /grpc.testing.BenchmarkService/UnaryCall'
23.1121 info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
      Executing endpoint 'gRPC - /grpc.testing.BenchmarkService/UnaryCall'
23.1122 dbug: Grpc.AspNetCore.Server.ServerCallHandler[10]
      Reading message.
23.1122 dbug: Microsoft.AspNetCore.Server.Kestrel[25]
      Connection id "0HMJ31P1V8BHG", Request id "0HMJ31P1V8BHG:00000000": started reading request body.
23.1122 trce: Grpc.AspNetCore.Server.ServerCallHandler[12]
      Deserializing 2 byte message to 'Grpc.Testing.SimpleRequest'.
23.1122 trce: Grpc.AspNetCore.Server.ServerCallHandler[13]
      Received message.
23.1129 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#29809623,NativeCallback,[strm][0x29C459C94D0] Stream received event RECEIVE ->
23.1129 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#29809623,HandleEventReceive,[strm][0x29C459C94D0] Stream received 0 bytes with FIN flag ->
23.1129 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#29809623,NativeCallback,[strm][0x29C459C94D0] Stream received event PEER_SEND_SHUTDOWN ->
23.1129 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#29809623,HandleEventPeerSendShutdown,[strm][0x29C459C94D0] Stream completing resettable event source. ->
23.1129 dbug: Microsoft.AspNetCore.Server.Kestrel[26]
      Connection id "0HMJ31P1V8BHG", Request id "0HMJ31P1V8BHG:00000000": done reading request body.
23.1130 trce: Microsoft.AspNetCore.Server.Kestrel.Http3[47]
      Connection id "0HMJ31P1V8BHG" sending HEADERS frame for stream ID 0 with length 76.
23.1130 dbug: Grpc.AspNetCore.Server.ServerCallHandler[15]
      Sending message.
23.1130 trce: Grpc.AspNetCore.Server.ServerCallHandler[18]
      Serialized 'Grpc.Testing.SimpleResponse' to 2 byte message.
23.1130 trce: Grpc.AspNetCore.Server.ServerCallHandler[16]
      Message sent.
23.1130 info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
      Executed endpoint 'gRPC - /grpc.testing.BenchmarkService/UnaryCall'
23.1130 trce: Microsoft.AspNetCore.Server.Kestrel.Http3[47]
      Connection id "0HMJ31P1V8BHG" sending DATA frame for stream ID 0 with length 7.
23.1131 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#29809623,NativeCallback,[strm][0x29C459C94D0] Stream received event SEND_COMPLETE ->
23.1132 trce: Microsoft.AspNetCore.Server.Kestrel.Http3[47]
      Connection id "0HMJ31P1V8BHG" sending HEADERS frame for stream ID 0 with length 17.
23.1132 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#29809623,NativeCallback,[strm][0x29C459C94D0] Stream received event SEND_COMPLETE ->
23.1133 info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished HTTP/3 POST https://localhost:5000/grpc.testing.BenchmarkService/UnaryCall application/grpc - - 200 - application/grpc 1.2488ms
23.1134 dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Quic[10]
      Stream id "0HMJ31P1V8BHG:00000000" shutting down writes because: "The QUIC transport's send loop completed gracefully.".
23.1401 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#29809623,NativeCallback,[strm][0x29C459C94D0] Stream received event SEND_SHUTDOWN_COMPLETE ->
23.1401 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#29809623,NativeCallback,[strm][0x29C459C94D0] Stream received event SHUTDOWN_COMPLETE ->
23.1401 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#29809623,HandleEventShutdownComplete,[strm][0x29C459C94D0] Stream completing resettable event source. ->
23.1402 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#29809623,Dispose,[strm][0x29C459C94D0] Stream disposing True ->
23.1403 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#29809623,Cleanup,[strm][0x29C459C94D0] releasing handles. ->
23.1403 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : SafeMsQuicStreamHandle#14836038,ReleaseHandle,MsQuicSafeHandle released ->
23.1403 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#29809623,Dispose,[strm][0x29C459C94D0] Stream disposed ->

Failure logs:

43.0608 dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Quic[2]
      Stream id "0HMJ31P1V8BHF:00000000" type Bidirectional accepted.
43.0610 trce: Microsoft.AspNetCore.Server.Kestrel.Http3[46]
      Connection id "0HMJ31P1V8BHF" received HEADERS frame for stream ID 0 with length 251.
43.0611 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#3891103,NativeCallback,[strm][0x29C459C9A70] Stream received event RECEIVE ->
43.0612 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#3891103,HandleEventReceive,[strm][0x29C459C9A70] Stream received 7 bytes ->
43.0613 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#3891103,ReadAsync,[strm][0x29C459C9A70] Stream reading into Memory of '4096' bytes. ->
43.0613 trce: Microsoft.AspNetCore.Server.Kestrel.Http3[46]
      Connection id "0HMJ31P1V8BHF" received DATA frame for stream ID 0 with length 7.
43.0614 info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/3 POST https://localhost:5000/grpc.testing.BenchmarkService/UnaryCall application/grpc -
43.0614 trce: Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware[2]
      All hosts are allowed.
43.0615 dbug: Microsoft.AspNetCore.Routing.Matching.DfaMatcher[1001]
      1 candidate(s) found for the request path '/grpc.testing.BenchmarkService/UnaryCall'
43.0615 dbug: Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware[1]
      Request matched endpoint 'gRPC - /grpc.testing.BenchmarkService/UnaryCall'
43.0615 info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
      Executing endpoint 'gRPC - /grpc.testing.BenchmarkService/UnaryCall'
43.0615 dbug: Grpc.AspNetCore.Server.ServerCallHandler[10]
      Reading message.
43.0615 dbug: Microsoft.AspNetCore.Server.Kestrel[25]
      Connection id "0HMJ31P1V8BHF", Request id "0HMJ31P1V8BHF:00000000": started reading request body.
43.0615 trce: Grpc.AspNetCore.Server.ServerCallHandler[12]
      Deserializing 2 byte message to 'Grpc.Testing.SimpleRequest'.
43.0615 trce: Grpc.AspNetCore.Server.ServerCallHandler[13]
      Received message.
43.0624 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#3891103,NativeCallback,[strm][0x29C459C9A70] Stream received event RECEIVE ->
43.0624 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#3891103,HandleEventReceive,[strm][0x29C459C9A70] Stream received 0 bytes with FIN flag ->
43.0624 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#3891103,NativeCallback,[strm][0x29C459C9A70] Stream received event PEER_SEND_SHUTDOWN ->
43.0624 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#3891103,HandleEventPeerSendShutdown,[strm][0x29C459C9A70] Stream completing resettable event source. ->
43.0625 dbug: Microsoft.AspNetCore.Server.Kestrel[26]
      Connection id "0HMJ31P1V8BHF", Request id "0HMJ31P1V8BHF:00000000": done reading request body.
43.0625 trce: Microsoft.AspNetCore.Server.Kestrel.Http3[47]
      Connection id "0HMJ31P1V8BHF" sending HEADERS frame for stream ID 0 with length 76.
43.0625 dbug: Grpc.AspNetCore.Server.ServerCallHandler[15]
      Sending message.
43.0626 trce: Grpc.AspNetCore.Server.ServerCallHandler[18]
      Serialized 'Grpc.Testing.SimpleResponse' to 2 byte message.
43.0626 trce: Grpc.AspNetCore.Server.ServerCallHandler[16]
      Message sent.
43.0626 info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
      Executed endpoint 'gRPC - /grpc.testing.BenchmarkService/UnaryCall'
43.0626 trce: Microsoft.AspNetCore.Server.Kestrel.Http3[47]
      Connection id "0HMJ31P1V8BHF" sending DATA frame for stream ID 0 with length 7.
43.0627 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#3891103,NativeCallback,[strm][0x29C459C9A70] Stream received event SEND_COMPLETE ->
43.0627 trce: Microsoft.AspNetCore.Server.Kestrel.Http3[47]
      Connection id "0HMJ31P1V8BHF" sending HEADERS frame for stream ID 0 with length 17.
43.0628 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#3891103,NativeCallback,[strm][0x29C459C9A70] Stream received event SEND_COMPLETE ->
43.0628 info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished HTTP/3 POST https://localhost:5000/grpc.testing.BenchmarkService/UnaryCall application/grpc - - 200 - application/grpc 1.3970ms
43.0629 dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Quic[10]
      Stream id "0HMJ31P1V8BHF:00000000" shutting down writes because: "The QUIC transport's send loop completed gracefully.".

The request then hangs, waiting on the task that doesn't complete. After 5 seconds Kestrel aborts the connection which calls QuicConnection.CloseAsync which unsticks WaitForWriteCompletionAsync and the task completes.

Logs after abort:

02.0392 dbug: Microsoft.AspNetCore.Server.Kestrel.BadRequests[28]
      Connection id "0HMJ330OH884L", Request id "0HMJ330OH884L:00000000": the connection was closed because the response was not read by the client at the specified minimum data rate.
06.7638 dbug: Microsoft.AspNetCore.Server.Kestrel.Http3[53]
      Connection id "0HMJ330OH884L": GOAWAY stream ID 4.
06.7638 trce: Microsoft.AspNetCore.Server.Kestrel.Http3[47]
      Connection id "0HMJ330OH884L" sending GOAWAY frame for stream ID 3 with length 1.
06.7639 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#16104161,NativeCallback,[strm][0x294D85D0760] Stream received event SEND_COMPLETE ->
06.7639 dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Quic[6]
      Connection id "0HMJ330OH884L" aborted by application with error code 258 because: "The connection was timed out by the server because the response was not read by the client at the specified minimum data rate.".
06.7640 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#33397131,NativeCallback,[strm][0x294D85D1840] Stream received event SEND_SHUTDOWN_COMPLETE ->
06.7640 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#33397131,NativeCallback,[strm][0x294D85D1840] Stream received event SHUTDOWN_COMPLETE ->
06.7640 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#33397131,HandleEventConnectionClose,[strm][0x294D85D1840] Stream handling connection [conn][0x294D8698DD0] close ->
06.7647 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#31139921,NativeCallback,[strm][0x294D85D0A30] Stream received event SHUTDOWN_COMPLETE ->
06.7647 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#31139921,HandleEventConnectionClose,[strm][0x294D85D0A30] Stream handling connection [conn][0x294D8698DD0] close ->
06.7657 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#16104161,NativeCallback,[strm][0x294D85D0760] Stream received event SEND_SHUTDOWN_COMPLETE ->
06.7657 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#16104161,NativeCallback,[strm][0x294D85D0760] Stream received event SHUTDOWN_COMPLETE ->
06.7657 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#16104161,HandleEventConnectionClose,[strm][0x294D85D0760] Stream handling connection [conn][0x294D8698DD0] close ->
06.7822 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#33397131,Dispose,[strm][0x294D85D1840] Stream disposing True ->
06.7822 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#33397131,Cleanup,[strm][0x294D85D1840] releasing handles. ->
06.7822 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : SafeMsQuicStreamHandle#6849668,ReleaseHandle,MsQuicSafeHandle released ->
06.7822 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#33397131,Dispose,[strm][0x294D85D1840] Stream disposed ->
06.7995 dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Quic[10]
      Stream id "0HMJ330OH884L:00000003" shutting down writes because: "Operation aborted.".
07.0183 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#45133484,NativeCallback,[conn][0x294D8698DD0] Connection received event SHUTDOWN_COMPLETE ->
07.0741 dbug: Microsoft.AspNetCore.Server.Kestrel.BadRequests[20]
      Connection id "0HMJ330OH884L" request processing ended abnormally.
      Microsoft.AspNetCore.Connections.ConnectionAbortedException: The connection was timed out by the server because the response was not read by the client at the specified minimum data rate.
         at Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Internal.QuicConnectionContext.AcceptAsync(CancellationToken cancellationToken)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http3.Http3Connection.ProcessRequestsAsync[TContext](IHttpApplication`1 application)
07.0743 dbug: Microsoft.AspNetCore.Server.Kestrel.Http3[44]
      Connection id "0HMJ330OH884L" is closed. The last processed stream ID was 0.
07.0744 dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[2]
      Connection id "0HMJ330OH884L" stopped.
07.0744 dbug: HttpEventSourceListener[0]
      <- Event Private.InternalDiagnostics.System.Net.Quic - Info : State#45133484,Dispose,[conn][0x294D8698DD0] Connection disposing True ->

Regression?

Unknown

Known Workarounds

No response

Configuration

Latest .NET 7 daily build

Other information

No response

Activity

  1. ghost added
    untriaged
    on Jul 11, 2022
  2. JamesNK commented on Jul 11, 2022

    @JamesNK
    MemberAuthor

    BTW fixing this is a high priority. The bug doesn't impact the HTTP/3 request because it has told the client it is complete, but 5 seconds later the HTTP/3 connection is aborted.

  3. ManickaP commented on Jul 11, 2022

    @ManickaP
    Member

    Could you point me to the test code for this? Looks like SEND_SHUTDOWN_COMPLETE hasn't arrived in your failed case.

  4. ManickaP commented on Jul 11, 2022

    @ManickaP
    Member

    Is this a recent regression or has it been there for a while?

  5. JamesNK commented on Jul 11, 2022

    @JamesNK
    MemberAuthor

    I first noticed it 23 days ago. I don't know if it happened before then.

  6. removed
    untriaged
    on Jul 14, 2022
  7. added this to the 7.0.0 milestone on Jul 14, 2022
  8. ManickaP commented on Jul 14, 2022

    @ManickaP
    Member

    Triage: looks like reliability issue, let's investigate in 7.0. It should be fairly simple to reproduce locally.

  9. self-assigned this
    on Jul 14, 2022
  10. CarnaViire commented on Jul 18, 2022

    @CarnaViire
    Member

    I can reproduce that, and indeed this is because SEND_SHUTDOWN_COMPLETE sometimes does not arrive to the server's stream.

    While digging through MsQuic logs, I noticed that client side didn't send ACK for server's FIN flag before destroying the stream:

    SERVER: sends FIN flag

    2387 [4]3A44.5574::2022/07/18-14:38:26.406710900 [Microsoft-Quic][strm][0x240A42A4BF0] Built stream frame, offset=107 len=0 fin=1
    
    2389 [4]3A44.5574::2022/07/18-14:38:26.406715700 [Microsoft-Quic][S][TX][16] SH DestCid: KP:0 SB:1 (Payload 15 bytes)
    2390 [4]3A44.5574::2022/07/18-14:38:26.406717600 [Microsoft-Quic][S][TX][16]   ACK Largest:14 Delay:0
    2391 [4]3A44.5574::2022/07/18-14:38:26.406719000 [Microsoft-Quic][S][TX][16]     14
    2392 [4]3A44.5574::2022/07/18-14:38:26.406721200 [Microsoft-Quic][S][TX][16]   STREAM ID:0 Offset:107 Len:0 Fin
    
    2401 [4]3A44.5574::2022/07/18-14:38:26.406733200 [Microsoft-Quic][conn][0x240A4218640] Sending batch. 1 datagrams
    

    CLIENT: receives the FIN flag datagram

    2422 [8]2AC4.6420::2022/07/18-14:38:26.406881200 [Microsoft-Quic][conn][0x21E299B6F00] Batch Recv 1 UDP datagrams
    
    2424 [8]2AC4.6420::2022/07/18-14:38:26.406886200 [Microsoft-Quic][C][RX][16] SH DestCid: KP:0 SB:1 (Payload 15 bytes)
    2425 [8]2AC4.6420::2022/07/18-14:38:26.406888200 [Microsoft-Quic][C][RX][16]   ACK Largest:14 Delay:0
    2426 [8]2AC4.6420::2022/07/18-14:38:26.406889600 [Microsoft-Quic][C][RX][16]     14
    2427 [8]2AC4.6420::2022/07/18-14:38:26.406891600 [Microsoft-Quic][C][RX][16]   STREAM ID:0 Offset:107 Len:0 Fin
    
    2428 [8]2AC4.6420::2022/07/18-14:38:26.406892500 [Microsoft-Quic][conn][0x21E299B6F00][RX][16] 5(ONE_RTT) (16 bytes)
    
    2434 [8]2AC4.6420::2022/07/18-14:38:26.406901600 [Microsoft-Quic][strm][0x21E29D79700] Received 0 bytes, offset=107 Ready=0
    

    ...marks for ACK but decides not to do that immediately

    2436 [8]2AC4.6420::2022/07/18-14:38:26.406904000 [Microsoft-Quic][C][RX][16] Marked for ACK (ECN=0)
    2437 [8]2AC4.6420::2022/07/18-14:38:26.406905500 [Microsoft-Quic][conn][0x21E299B6F00] Starting ACK_DELAY timer for 25 ms
    

    ...as now both of stream's directions are shut down, triggers last events

    2468 [8]2AC4.6420::2022/07/18-14:38:26.424288300 [Microsoft-Quic][strm][0x21E29D79700] Indicating QUIC_STREAM_EVENT_PEER_SEND_SHUTDOWN
    2469 [8]2AC4.6420::2022/07/18-14:38:26.424304800 [Microsoft-Quic][strm][0x21E29D79700] Indicating QUIC_STREAM_EVENT_SHUTDOWN_COMPLETE [ConnectionShutdown=0, ConnectionShutdownByPeer=0, ConnectionErrorCode=0x0]
    
    2473 [0]2AC4.6260::2022/07/18-14:38:26.426986800 [Microsoft-Quic][ api] Enter 21(STREAM_SHUTDOWN) (0x21E29D79700).
    2476 [0]2AC4.6260::2022/07/18-14:38:26.427000700 [Microsoft-Quic][ api] Enter 19(STREAM_CLOSE) (0x21E29D79700).
    
    2485 [8]2AC4.6420::2022/07/18-14:38:26.427042200 [Microsoft-Quic][strm][0x21E29D79700] Destroyed
    

    ...after stream being destroyed, it seems that it forgot to send that delayed ACK to the peer.... it was scheduled for ~14:38:26.431 but stream was destroyed at 14:38:26.427

    SERVER: did not hear from client, tries to retransmit FIN..... no response, it isn't even shown on client connection's logs (I guess it disregards datagrams addressed to already closed streams)

    Full MsQuic logs

    https://microsofteur-my.sharepoint.com/:f:/g/personal/knatalia_microsoft_com/EsnkYxGB26BKmRrIOh7va-4B8Ezq6elWQTPy-WAuV5-ZBw?e=Qu3hKO

    @nibanks does that look like MsQuic bug?

  11. nibanks commented on Jul 18, 2022

    @nibanks

    @CarnaViire was the stream aborted? I see that Ready=0 when the client receives the FIN, indicating you have a pending receive or are missing some payload and can't deliver yet. But regardless, I believe this means we're blocked from informing the app that we have the FIN. If the client aborts its receive first, then you won't get the FIN.

  12. nibanks commented on Jul 18, 2022

    @nibanks

    Actually, after looking at the logs, it seems the client just stopped all together. It's not receiving any other packets. This is with a breakpoint attached to it?

  13. 15 remaining items

  14. added
    tracking-external-issue
    on Aug 2, 2022
  15. karelz commented on Aug 2, 2022

    @karelz
    Member

    Triage: We had a meeting where we decided the scenario is fairly corner-case (Kestrel users won't see anything, unless they enable Diagnostics).
    It would still be nice to have it implemented in msquic, but it is nice to have. Playing nicely with the server is desirable.

    Moving to 8.0. If we have customer complains from the wild, we can always service .NET.

  16. CarnaViire commented on Nov 21, 2022

    @CarnaViire
    Member

    Triage: we need to create an issue in MsQuic repo and link the PR microsoft/msquic#2904 there + mention that in order for it to work, the code should be in Close, not Shutdown (see comment above).

  17. removed their assignment
    on Nov 21, 2022
  18. ManickaP commented on Jan 19, 2023

    @ManickaP
    Member

    Triage: the last comment stands.

  19. wfurt commented on May 1, 2023

    @wfurt
    Member

    Did we created new issue @CarnaViire or is this something that was fixed in 2.2? I cannot quite tell and I'm not sure what is next step here.

  20. ValeryYegorov commented on Jun 15, 2023

    @ValeryYegorov

    Hello
    I thought we have same issues on Ios(client) -> linux(sever) architecture.
    Issues opened on grpc/grpc-dotnet#2164 and microsoft/msquic#3703

  21. modified the milestones: 8.0.0, 9.0.0 on Aug 14, 2023
  22. CarnaViire commented on Sep 7, 2023

    @CarnaViire
    Member
  23. removed their assignment
    on Sep 7, 2023
  24. modified the milestones: 9.0.0, Future on Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Net.Quicbugtracking-external-issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions