diff --git a/src/coreclr/jit/hwintrinsicxarch.cpp b/src/coreclr/jit/hwintrinsicxarch.cpp index 89a2b1ba6042d4..be013b67fe3cd2 100644 --- a/src/coreclr/jit/hwintrinsicxarch.cpp +++ b/src/coreclr/jit/hwintrinsicxarch.cpp @@ -267,18 +267,24 @@ static CORINFO_InstructionSet lookupInstructionSet(const char* className) { if (strncmp(className + 6, "128", 3) == 0) { - assert((className[9] == '\0') || (strcmp(className + 9, "`1") == 0)); - return InstructionSet_Vector128; + if ((className[9] == '\0') || (strcmp(className + 9, "`1") == 0)) + { + return InstructionSet_Vector128; + } } else if (strncmp(className + 6, "256", 3) == 0) { - assert((className[9] == '\0') || (strcmp(className + 9, "`1") == 0)); - return InstructionSet_Vector256; + if ((className[9] == '\0') || (strcmp(className + 9, "`1") == 0)) + { + return InstructionSet_Vector256; + } } else if (strncmp(className + 6, "512", 3) == 0) { - assert((className[9] == '\0') || (strcmp(className + 9, "`1") == 0)); - return InstructionSet_Vector512; + if ((className[9] == '\0') || (strcmp(className + 9, "`1") == 0)) + { + return InstructionSet_Vector512; + } } } else if (strcmp(className, "VL") == 0) diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicListener.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicListener.cs index 5c148b7b4e4765..c0bdb22aa1ae63 100644 --- a/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicListener.cs +++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicListener.cs @@ -225,9 +225,9 @@ private async void StartConnectionHandshake(QuicConnection connection, SslClient // https://github.com/microsoft/msquic/discussions/2705. // This will be assigned to before the linked CTS is cancelled TimeSpan handshakeTimeout = QuicDefaults.HandshakeTimeout; + using CancellationTokenSource linkedCts = CancellationTokenSource.CreateLinkedTokenSource(_disposeCts.Token, connection.ConnectionShutdownToken); try { - using CancellationTokenSource linkedCts = CancellationTokenSource.CreateLinkedTokenSource(_disposeCts.Token, connection.ConnectionShutdownToken); cancellationToken = linkedCts.Token; // Initial timeout for retrieving connection options. linkedCts.CancelAfter(handshakeTimeout); @@ -249,7 +249,7 @@ private async void StartConnectionHandshake(QuicConnection connection, SslClient await connection.DisposeAsync().ConfigureAwait(false); } } - catch (OperationCanceledException) when (connection.ConnectionShutdownToken.IsCancellationRequested) + catch (OperationCanceledException) when (connection.ConnectionShutdownToken.IsCancellationRequested && !linkedCts.IsCancellationRequested) { // Connection closed by peer if (NetEventSource.Log.IsEnabled()) diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.cs index c2469482c130cf..a0713d3b8f9bb8 100644 --- a/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.cs +++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.IO; using System.Runtime.CompilerServices; +using System.Runtime.ExceptionServices; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -359,13 +360,16 @@ public override ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationTo /// The region of memory to write data from. /// The token to monitor for cancellation requests. The default value is . /// Notifies the peer about gracefully closing the write side, i.e.: sends FIN flag with the data. - public async ValueTask WriteAsync(ReadOnlyMemory buffer, bool completeWrites, CancellationToken cancellationToken = default) + public ValueTask WriteAsync(ReadOnlyMemory buffer, bool completeWrites, CancellationToken cancellationToken = default) { - ObjectDisposedException.ThrowIf(_disposed == 1, this); + if (_disposed == 1) + { + return ValueTask.FromException(ExceptionDispatchInfo.SetCurrentStackTrace(new ObjectDisposedException(nameof(QuicStream)))); + } if (!_canWrite) { - throw new InvalidOperationException(SR.net_quic_writing_notallowed); + return ValueTask.FromException(ExceptionDispatchInfo.SetCurrentStackTrace(new InvalidOperationException(SR.net_quic_writing_notallowed))); } if (NetEventSource.Log.IsEnabled()) @@ -373,24 +377,23 @@ public async ValueTask WriteAsync(ReadOnlyMemory buffer, bool completeWrit NetEventSource.Info(this, $"{this} Stream writing memory of '{buffer.Length}' bytes while {(completeWrites ? "completing" : "not completing")} writes."); } - if (_sendTcs.IsCompleted) + if (_sendTcs.IsCompleted && cancellationToken.IsCancellationRequested) { // Special case exception type for pre-canceled token while we've already transitioned to a final state and don't need to abort write. // It must happen before we try to get the value task, since the task source is versioned and each instance must be awaited. - cancellationToken.ThrowIfCancellationRequested(); + return ValueTask.FromCanceled(cancellationToken); } // Concurrent call, this one lost the race. if (!_sendTcs.TryGetValueTask(out ValueTask valueTask, this, cancellationToken)) { - throw new InvalidOperationException(SR.Format(SR.net_io_invalidnestedcall, "write")); + return ValueTask.FromException(ExceptionDispatchInfo.SetCurrentStackTrace(new InvalidOperationException(SR.Format(SR.net_io_invalidnestedcall, "write")))); } // No need to call anything since we already have a result, most likely an exception. if (valueTask.IsCompleted) { - await valueTask.ConfigureAwait(false); - return; + return valueTask; } // For an empty buffer complete immediately, close the writing side of the stream if necessary. @@ -401,8 +404,7 @@ public async ValueTask WriteAsync(ReadOnlyMemory buffer, bool completeWrit { CompleteWrites(); } - await valueTask.ConfigureAwait(false); - return; + return valueTask; } // We own the lock, abort might happen, but exception will get stored instead. @@ -438,7 +440,7 @@ public async ValueTask WriteAsync(ReadOnlyMemory buffer, bool completeWrit } } - await valueTask.ConfigureAwait(false); + return valueTask; } /// diff --git a/src/native/managed/native-library.props b/src/native/managed/native-library.props index 7acadfa32d4247..41dae2155f509b 100644 --- a/src/native/managed/native-library.props +++ b/src/native/managed/native-library.props @@ -7,6 +7,7 @@ --> false true + Guard