dotnet/aspnetcore

connection Abort + Dispose crashes process

Open

#57 098 ouverte le 31 juil. 2024

Voir sur GitHub
 (2 commentaires) (1 réaction) (0 assignés)C# (10 653 forks)batch import
area-networkinghelp wanted

Métriques du dépôt

Stars
 (37 933 stars)
Métriques de merge PR
 (Merge moyen 16j 9h) (258 PRs mergées en 30 j)

Description

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I implemented A custom protocol and when I try to close an incoming connection my process crashes

Expected Behavior

Im able to close a connection.

Steps To Reproduce

[TestMethod]
public async Task TestCancelConnection()
{
    var connection = new DefaultConnectionContext();
    connection.Abort();
    await connection.DisposeAsync();

    await Task.Delay(TimeSpan.FromSeconds(1));
}

https://github.com/dotnet/aspnetcore/blob/6dc454f9079ff8d4b268b7e307dd14a05917e903/src/Servers/Connections.Abstractions/src/DefaultConnectionContext.cs#L101

looks like this should have a catch or something that does not blow up if the connection is disposed

Exceptions (if any)

The active test run was aborted. Reason: Test host process crashed : Unhandled exception. System.ObjectDisposedException: The CancellationTokenSource has been disposed. at System.Threading.CancellationTokenSource.Cancel() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()

.NET Version

8.0.6

Anything else?

No response

Guide contributeur