runtime: HTTP2: Hang when concurrent calls with cancellation

Description

Grpc.Net.Client (which uses HttpClient internally) is hanging when there are 20 concurrent calls with cancellation happening in a loop.

Repo: repos.zip

  1. Extract to directory
  2. dotnet run -p GrpcService28
  3. dotnet run -p ConsoleApp50
  4. ConsoleApp will throw timeout exceptions after a few hundred/thousand iterations.

Changing ConsoleApp50 target framework from net5.0 to netcoreapp3.1 fixes the timeout exceptions.

Normally I’d attempt to remove Grpc.Net.Client library from the repo, but in this case the gRPC call is using a number of fairly advanced features (bidi streaming, cancellation) so I have left it in.

What console app is doing (20 parallel threads on one HTTP/2 connection):

  1. Starting bidi streaming call, client.EchoAllData(cancellationToken: cts.Token, headers: headers)
  2. Waiting for the call response headers from server, await call.ResponseHeadersAsync.DefaultTimeout();
  3. Writing 64kb message, await call.RequestStream.WriteAsync(...) <- this is where the hang happens
  4. Cancelling call, cts.Cancel();
  5. Go to 1

Configuration

Using nightly SDK: 5.0.100-rc.1.20367.2

Regression?

Yes, this worked in netcoreapp3.1

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (17 by maintainers)

Most upvoted comments

Not needed. The gRPC template has http on 5000, https on 5001, and both are HTTP/2 only because of appsettings.json.

  "Kestrel": {
    "EndpointDefaults": {
      "Protocols": "Http2"
    }
  }