diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/Managed/ManagedQuicConnection.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/Managed/ManagedQuicConnection.cs
index badaf724f73819..5c7ae8957591dc 100644
--- a/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/Managed/ManagedQuicConnection.cs
+++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/Managed/ManagedQuicConnection.cs
@@ -14,6 +14,7 @@
using System.Net.Quic.Implementations.Managed.Internal.Streams;
using System.Net.Quic.Implementations.Managed.Internal.Tracing;
using System.Net.Quic.Implementations.Managed.Internal.Tls;
+using System.Net.Quic.Implementations.Managed.Internal.Tls.OpenSsl;
using System.Net.Security;
using System.Threading;
using System.Threading.Tasks;
@@ -21,6 +22,8 @@
using System.Threading.Channels;
using System.Diagnostics.CodeAnalysis;
+#pragma warning disable IDE0060
+
namespace System.Net.Quic.Implementations.Managed
{
public sealed partial class ManagedQuicConnection : IAsyncDisposable
@@ -69,6 +72,8 @@ public sealed partial class ManagedQuicConnection : IAsyncDisposable
///
private bool IsClosing => _closingPeriodEndTimestamp != null;
+ private bool Connected => HandshakeConfirmed;
+
///
/// Timestamp when the connection close will be initiated due to lack of packets from peer.
///
@@ -607,7 +612,7 @@ internal ValueTask DisposeAsync(long errorCode)
if (!Connected)
{
// abandon connection attempt
- _connectTcs.TryCompleteException(new QuicException(QuicError.ConnectionAborted, errorCode));
+ _connectTcs.TryCompleteException(new QuicException(QuicError.ConnectionAborted, errorCode, "Abandon connection attempt"));
_closeTcs.TryComplete();
return default;
}
@@ -775,7 +780,7 @@ internal void ThrowIfError()
if (!_outboundError.IsQuicError)
{
// connection close initiated by application
- throw new QuicOperationAbortedException();
+ throw new QuicException(QuicError.ConnectionAborted, (long)_outboundError.ErrorCode, "Connection close initiated by application");
}
else if (_outboundError.ErrorCode != TransportErrorCode.NoError)
{
@@ -893,12 +898,12 @@ private QuicException MakeOperationAbortedException()
{
return _inboundError != null
? MakeConnectionAbortedException(_inboundError) // initiated by peer
- : new QuicOperationAbortedException(); // initiated by us
+ : new QuicException(QuicError.OperationAborted, null, "Initiated by us");
}
private static QuicException MakeConnectionAbortedException(QuicTransportError error)
{
- return new QuicException(QuicError.ConnectionAborted, (long)error.ErrorCode, error.ReasonPhrase);
+ return new QuicException(QuicError.ConnectionAborted, (long)error.ErrorCode, error.ReasonPhrase ?? "");
}
internal void OnSocketContextException(Exception e)
@@ -924,3 +929,5 @@ internal void DoCleanup()
}
}
}
+
+#pragma warning restore IDE0060
diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/Managed/ManagedQuicListener.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/Managed/ManagedQuicListener.cs
index 710e7323bbc3f8..8d0dd840c205b3 100644
--- a/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/Managed/ManagedQuicListener.cs
+++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/Managed/ManagedQuicListener.cs
@@ -5,6 +5,7 @@
using System.Net.Quic.Implementations.Managed.Internal;
using System.Net.Quic.Implementations.Managed.Internal.Sockets;
using System.Net.Quic.Implementations.Managed.Internal.Tls;
+using System.Net.Quic.Implementations.Managed.Internal.Tls.OpenSsl;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
@@ -51,11 +52,13 @@ public ValueTask AcceptConnectionAsync(CancellationToken
public ValueTask DisposeAsync()
{
- if (_disposed) return;
-
+ if (_disposed) return ValueTask.CompletedTask;
+
_disposed = true;
_socketContext.StopOrOrphan();
+
+ return ValueTask.CompletedTask;
}
}
}