Skip to content

Commit 9ed6d99

Browse files
authored
[QUIC] Improved logic of listener AcceptConnection (#82261)
* Slow connection handshakes do not stall any connections in accept queue. * Listener tests * PR feedback * Test fix attempt
1 parent ac7afb9 commit 9ed6d99

File tree

8 files changed

+355
-128
lines changed

8 files changed

+355
-128
lines changed

src/libraries/System.Net.Quic/src/Resources/Strings.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@
171171
<data name="net_quic_timeout" xml:space="preserve">
172172
<value>Connection timed out waiting for a response from the peer.</value>
173173
</data>
174+
<data name="net_quic_handshake_timeout" xml:space="preserve">
175+
<value>Connection handshake was canceled due to the configured timeout of {0} seconds elapsing.</value>
176+
</data>
174177
<data name="net_quic_ssl_option" xml:space="preserve">
175178
<value>'{0}' is not supported by System.Net.Quic.</value>
176179
</data>
@@ -220,7 +223,7 @@
220223
<value>Binding to socket failed, likely caused by a family mismatch between local and remote address.</value>
221224
</data>
222225
<data name="net_quic_auth" xml:space="preserve">
223-
<value>Authentication failed. {0}</value>
226+
<value>Authentication failed: {0}.</value>
224227
</data>
225228
<!-- Same as in System.Net.Security -->
226229
<data name="net_io_invalidnestedcall" xml:space="preserve">

src/libraries/System.Net.Quic/src/System/Net/Quic/QuicConnection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ public async ValueTask<QuicStream> AcceptInboundStreamAsync(CancellationToken ca
399399
}
400400
catch (ChannelClosedException ex) when (ex.InnerException is not null)
401401
{
402-
ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
402+
ExceptionDispatchInfo.Throw(ex.InnerException);
403403
throw;
404404
}
405405
finally
@@ -608,7 +608,7 @@ private static unsafe int NativeCallback(QUIC_HANDLE* connection, void* context,
608608
}
609609

610610
/// <summary>
611-
/// If not closed explicitly by <see cref="CloseAsync(long, CancellationToken)" />, closes the connection silently (leading to idle timeout on the peer side).
611+
/// If not closed explicitly by <see cref="CloseAsync(long, CancellationToken)" />, closes the connection with the <see cref="QuicConnectionOptions.DefaultCloseErrorCode"/>.
612612
/// And releases all resources associated with the connection.
613613
/// </summary>
614614
/// <returns>A task that represents the asynchronous dispose operation.</returns>
@@ -619,7 +619,7 @@ public async ValueTask DisposeAsync()
619619
return;
620620
}
621621

622-
// Check if the connection has been shut down and if not, shut it down silently.
622+
// Check if the connection has been shut down and if not, shut it down.
623623
if (_shutdownTcs.TryInitialize(out ValueTask valueTask, this))
624624
{
625625
unsafe

src/libraries/System.Net.Quic/src/System/Net/Quic/QuicDefaults.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ internal static partial class QuicDefaults
3232
/// Max value for application error codes that can be sent by QUIC, see <see href="https://www.rfc-editor.org/rfc/rfc9000.html#integer-encoding"/>.
3333
/// </summary>
3434
public const long MaxErrorCodeValue = (1L << 62) - 1;
35+
36+
/// <summary>
37+
/// Our own imposed timeout in the handshake process, since in certain cases MsQuic will not impose theirs, see <see href="https://github.com/microsoft/msquic/discussions/2705"/>.
38+
/// </summary>
39+
public static readonly TimeSpan HandshakeTimeout = TimeSpan.FromSeconds(10);
3540
}

src/libraries/System.Net.Quic/src/System/Net/Quic/QuicException.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,18 @@ public sealed class QuicException : IOException
1717
/// <param name="applicationErrorCode">The application protocol error code associated with the error.</param>
1818
/// <param name="message">The message for the exception.</param>
1919
public QuicException(QuicError error, long? applicationErrorCode, string message)
20-
: base(message)
20+
: this(error, applicationErrorCode, message, null)
21+
{ }
22+
23+
/// <summary>
24+
/// Initializes a new instance of the <see cref='QuicException'/> class.
25+
/// </summary>
26+
/// <param name="error">The error associated with the exception.</param>
27+
/// <param name="applicationErrorCode">The application protocol error code associated with the error.</param>
28+
/// <param name="message">The message for the exception.</param>
29+
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
30+
internal QuicException(QuicError error, long? applicationErrorCode, string message, Exception? innerException)
31+
: base(message, innerException)
2132
{
2233
QuicError = error;
2334
ApplicationErrorCode = applicationErrorCode;

src/libraries/System.Net.Quic/src/System/Net/Quic/QuicListener.PendingConnection.cs

Lines changed: 0 additions & 107 deletions
This file was deleted.

0 commit comments

Comments
 (0)