Skip to content

.NET 8.0 ChannelClosedException using gRPC (Http2Connection) #95621

Closed

Description

@SHAZAM-Analytics

Description

Under .NET 8.0, if the connection is interrupted for any reason the Http2Connection FinalTeardown() method is called. This hits the Complete() method in ChannelWriter, which then fails to complete, throwing a ChannelClosedException. This exception cannot be caught by our application and so crashes the application.

This is a huge problem on .NET 8.0, via packages such as .NET gRPC, because a client can crash a server. Under .NET 7.0 this never happened.

As you can imagine there are any number of reasons that the connection can be interrupted, from network issues, network changes or problems with either the server or the client. Notably, if a client has an issue that triggers the Channel to close, this will immediately crash the server application.

Reproduction Steps

Create a call from a client to a server and interrupt it.... such as with a debugger breakpoint in a server. Wait until the connection times out and is closed and observe the client then crashing.

Expected behavior

A closed connection should not crash one (or both) of the parties in a communication. At the very least, the exception should be trappable.

Actual behavior

Crashes and hits our UnhandledException handler

       AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

Regression?

No issues with the same code in .NET 7.0

Known Workarounds

Revert to .NET 7.0

Configuration

This was triggered using the grpc-dotnet project. This makes using grpc a problem in .NET8.0.

Other information

Application: SA.SQA.Provision.exe
CoreCLR Version: 8.0.23.53103
.NET Version: 8.0.0
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Threading.Channels.ChannelClosedException: The channel has been closed.
at System.Net.Http.Http2Connection.FinalTeardown()
at System.Net.Http.Http2Connection.Shutdown()
at System.Net.Http.Http2Connection.Abort(Exception abortException)
at System.Net.Http.Http2Connection.HeartBeat()
at System.Net.Http.HttpConnectionPool.HeartBeat()
at System.Net.Http.HttpConnectionPoolManager.HeartBeat()
at System.Threading.TimerQueueTimer.Fire(Boolean isThreadPool)
at System.Threading.TimerQueue.FireNextTimers()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()

Activity

  1. ghost added
    untriaged
    on Dec 5, 2023
  2. self-assigned this
    on Dec 5, 2023
  3. removed
    untriaged
    on Dec 5, 2023
  4. added this to the 9.0.0 milestone on Dec 5, 2023
  5. IonutLupsan commented on Dec 12, 2023

    @IonutLupsan

    Seeing the 9.0.0 milestone added, is there any chance this will be addressed also for .NET8?

  6. CarnaViire commented on Dec 12, 2023

    @CarnaViire
    Member

    Hi @rupreck, can you please reach out to me via email that I have on my GitHub profile? I have some questions that would be easier to cover via email.
    @IonutLupsan feel free to contact me via email as well.

  7. self-assigned this
    on Dec 17, 2023
  8. added
    tenet-reliability
    on Dec 17, 2023
  9. ghost added
    in-pr
    on Dec 19, 2023
  10. MihaZupan commented on Dec 19, 2023

    @MihaZupan
    Member

    Fixed in main for 9.0 in #96157.
    Backported to 8.0 in #96158.

  11. modified the milestones: 9.0.0, 8.0.x on Dec 19, 2023
  12. jaydoshiforblog commented on Jan 3, 2024

    @jaydoshiforblog

    Is this issue related IIS or Kestrel server?

  13. MihaZupan commented on Jan 3, 2024

    @MihaZupan
    Member

    This is an issue in HttpClient, not the servers.

  14. ghost removed
    in-pr
    on Jan 4, 2024
  15. xqrzd commented on Jan 16, 2024

    @xqrzd

    Are there any workarounds for this on .NET 8 until the patch is available? Is it possible to disable KeepAlive, or would creating/disposing a new GrpcChannel for every request fix the issue?

  16. MihaZupan commented on Jan 16, 2024

    @MihaZupan
    Member

    Disabling HTTP/2 pings (keeping SocketsHttpHandlr.KeepAlivePingDelay on its default of infinite) would avoid this issue.

  17. locked and limited conversation to collaborators on Feb 16, 2024
  18. karelz commented on Jun 24, 2024

    @karelz
    Member

    Fixed in main (9.0) in PR #96157 and in 8.0.2 in PR #96158.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-System.Net.Httpbugregression-from-last-releasetenet-reliability

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions