From 7f34be5319af78de3cb5fe12438f2756a864bddd Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Lopez <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 15 Jul 2020 13:10:46 -0700 Subject: [PATCH] Apply CA2016: Forward CancellationToken to methods that can take it (#37607) * Forward CancellationToken to methods that can take it * Address suggestions * address suggestions * Revert using * Make rule 2016 a warning in runtime * Extra cases found * Revert changes that should not pass a token, change rule to info to verify build and test CI results * Pass CancellationToken.None to base.CreateContentReadStreamAsync, as in its default overload * Address stack overflow in MultipartContent * HostingAbstractionsHostExtensions address using * Update nuget package version to latest, Info->Warning again, fix one more case. * System.Diagnostics.ProcessWaitState.Unix token * Remove two unnecessary tokens --- eng/Analyzers.props | 2 +- eng/CodeAnalysis.ruleset | 2 +- .../Quic/Implementations/Mock/MockConnection.cs | 4 ++-- .../Quic/Implementations/Mock/MockListener.cs | 2 +- .../src/System/Net/WebSockets/ManagedWebSocket.cs | 2 +- .../src/HostingAbstractionsHostExtensions.cs | 8 ++++--- .../Collections/Concurrent/BlockingCollection.cs | 2 +- .../System/Diagnostics/ProcessWaitState.Unix.cs | 4 ++-- .../IO/Compression/dec/BrotliStream.Decompress.cs | 3 ++- .../IsolatedStorage/IsolatedStorageFileStream.cs | 2 +- .../src/System.Net.Http.Json.csproj | 2 ++ .../Net/Http/Json/HttpContentJsonExtensions.cs | 18 +++++----------- .../Json/HttpContentJsonExtensions.netcoreapp.cs | 24 +++++++++++++++++++++ .../Json/HttpContentJsonExtensions.netstandard.cs | 25 ++++++++++++++++++++++ .../Http/BrowserHttpHandler/BrowserHttpHandler.cs | 4 ++-- .../System/Net/Http/MessageProcessingHandler.cs | 2 +- .../src/System/Net/Http/MultipartContent.cs | 4 +++- .../SocketsHttpHandler/DecompressionHandler.cs | 3 ++- .../Http/SocketsHttpHandler/Http3RequestStream.cs | 2 +- .../System/Net/Windows/WebSockets/WebSocketBase.cs | 2 +- .../src/System/IO/FileStream.Unix.cs | 2 +- .../Channels/SingleConsumerUnboundedChannel.cs | 4 ++-- 22 files changed, 86 insertions(+), 37 deletions(-) create mode 100644 src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.netcoreapp.cs create mode 100644 src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.netstandard.cs diff --git a/eng/Analyzers.props b/eng/Analyzers.props index 8d2a67c..2c9b1c8 100644 --- a/eng/Analyzers.props +++ b/eng/Analyzers.props @@ -6,7 +6,7 @@ - + diff --git a/eng/CodeAnalysis.ruleset b/eng/CodeAnalysis.ruleset index e88f8fc..42ea385 100644 --- a/eng/CodeAnalysis.ruleset +++ b/eng/CodeAnalysis.ruleset @@ -122,7 +122,7 @@ - + diff --git a/src/libraries/Common/src/System/Net/Http/aspnetcore/Quic/Implementations/Mock/MockConnection.cs b/src/libraries/Common/src/System/Net/Http/aspnetcore/Quic/Implementations/Mock/MockConnection.cs index 361474b..cba2f93 100644 --- a/src/libraries/Common/src/System/Net/Http/aspnetcore/Quic/Implementations/Mock/MockConnection.cs +++ b/src/libraries/Common/src/System/Net/Http/aspnetcore/Quic/Implementations/Mock/MockConnection.cs @@ -93,7 +93,7 @@ namespace System.Net.Quic.Implementations.Mock int bytesRead = 0; do { - bytesRead += await socket.ReceiveAsync(buffer.AsMemory().Slice(bytesRead), SocketFlags.None).ConfigureAwait(false); + bytesRead += await socket.ReceiveAsync(buffer.AsMemory().Slice(bytesRead), SocketFlags.None, cancellationToken).ConfigureAwait(false); } while (bytesRead != buffer.Length); int peerListenPort = BinaryPrimitives.ReadInt32LittleEndian(buffer); @@ -163,7 +163,7 @@ namespace System.Net.Quic.Implementations.Mock int bytesRead = 0; do { - bytesRead += await socket.ReceiveAsync(buffer.AsMemory().Slice(bytesRead), SocketFlags.None).ConfigureAwait(false); + bytesRead += await socket.ReceiveAsync(buffer.AsMemory().Slice(bytesRead), SocketFlags.None, cancellationToken).ConfigureAwait(false); } while (bytesRead != buffer.Length); long streamId = BinaryPrimitives.ReadInt64LittleEndian(buffer); diff --git a/src/libraries/Common/src/System/Net/Http/aspnetcore/Quic/Implementations/Mock/MockListener.cs b/src/libraries/Common/src/System/Net/Http/aspnetcore/Quic/Implementations/Mock/MockListener.cs index f4c0cfd..e7b2454 100644 --- a/src/libraries/Common/src/System/Net/Http/aspnetcore/Quic/Implementations/Mock/MockListener.cs +++ b/src/libraries/Common/src/System/Net/Http/aspnetcore/Quic/Implementations/Mock/MockListener.cs @@ -45,7 +45,7 @@ namespace System.Net.Quic.Implementations.Mock int bytesRead = 0; do { - bytesRead += await socket.ReceiveAsync(buffer.AsMemory().Slice(bytesRead), SocketFlags.None).ConfigureAwait(false); + bytesRead += await socket.ReceiveAsync(buffer.AsMemory().Slice(bytesRead), SocketFlags.None, cancellationToken).ConfigureAwait(false); } while (bytesRead != buffer.Length); int peerListenPort = BinaryPrimitives.ReadInt32LittleEndian(buffer); diff --git a/src/libraries/Common/src/System/Net/WebSockets/ManagedWebSocket.cs b/src/libraries/Common/src/System/Net/WebSockets/ManagedWebSocket.cs index e44b306..77e89ea 100644 --- a/src/libraries/Common/src/System/Net/WebSockets/ManagedWebSocket.cs +++ b/src/libraries/Common/src/System/Net/WebSockets/ManagedWebSocket.cs @@ -368,7 +368,7 @@ namespace System.Net.WebSockets // pass around (the CancellationTokenRegistration), so if it is cancelable, just immediately go to the fallback path. // Similarly, it should be rare that there are multiple outstanding calls to SendFrameAsync, but if there are, again // fall back to the fallback path. - return cancellationToken.CanBeCanceled || !_sendFrameAsyncLock.Wait(0) ? + return cancellationToken.CanBeCanceled || !_sendFrameAsyncLock.Wait(0, default) ? SendFrameFallbackAsync(opcode, endOfMessage, payloadBuffer, cancellationToken) : SendFrameLockAcquiredNonCancelableAsync(opcode, endOfMessage, payloadBuffer); } diff --git a/src/libraries/Microsoft.Extensions.Hosting.Abstractions/src/HostingAbstractionsHostExtensions.cs b/src/libraries/Microsoft.Extensions.Hosting.Abstractions/src/HostingAbstractionsHostExtensions.cs index ac0368b..f97c652 100644 --- a/src/libraries/Microsoft.Extensions.Hosting.Abstractions/src/HostingAbstractionsHostExtensions.cs +++ b/src/libraries/Microsoft.Extensions.Hosting.Abstractions/src/HostingAbstractionsHostExtensions.cs @@ -26,9 +26,10 @@ namespace Microsoft.Extensions.Hosting /// The timeout for stopping gracefully. Once expired the /// server may terminate any remaining active connections. /// The that represents the asynchronous operation. - public static Task StopAsync(this IHost host, TimeSpan timeout) + public static async Task StopAsync(this IHost host, TimeSpan timeout) { - return host.StopAsync(new CancellationTokenSource(timeout).Token); + using CancellationTokenSource cts = new CancellationTokenSource(timeout); + await host.StopAsync(cts.Token).ConfigureAwait(false); } /// @@ -103,7 +104,8 @@ namespace Microsoft.Extensions.Hosting await waitForStop.Task.ConfigureAwait(false); // Host will use its default ShutdownTimeout if none is specified. - await host.StopAsync().ConfigureAwait(false); + // The cancellation token may have been triggered to unblock waitForStop. Don't pass it here because that would trigger an abortive shutdown. + await host.StopAsync(CancellationToken.None).ConfigureAwait(false); } } } diff --git a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs index 7e6b08c..ec80b76 100644 --- a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs +++ b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs @@ -418,7 +418,7 @@ namespace System.Collections.Concurrent CancellationTokenSource? linkedTokenSource = null; try { - waitForSemaphoreWasSuccessful = _freeNodes.Wait(0); + waitForSemaphoreWasSuccessful = _freeNodes.Wait(0, default); if (waitForSemaphoreWasSuccessful == false && millisecondsTimeout != 0) { linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource( diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessWaitState.Unix.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessWaitState.Unix.cs index 1224636..03e93a7 100644 --- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessWaitState.Unix.cs +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessWaitState.Unix.cs @@ -500,7 +500,7 @@ namespace System.Diagnostics /// Spawns an asynchronous polling loop for process completion. /// A token to monitor to exit the polling loop. /// The task representing the loop. - private Task WaitForExitAsync(CancellationToken cancellationToken = default(CancellationToken)) + private Task WaitForExitAsync(CancellationToken cancellationToken = default) { Debug.Assert(Monitor.IsEntered(_gate)); Debug.Assert(_waitInProgress == null); @@ -549,7 +549,7 @@ namespace System.Diagnostics _waitInProgress = null; } } - }); + }, cancellationToken); } private bool TryReapChild() diff --git a/src/libraries/System.IO.Compression.Brotli/src/System/IO/Compression/dec/BrotliStream.Decompress.cs b/src/libraries/System.IO.Compression.Brotli/src/System/IO/Compression/dec/BrotliStream.Decompress.cs index 8b995f4..b5c86a0 100644 --- a/src/libraries/System.IO.Compression.Brotli/src/System/IO/Compression/dec/BrotliStream.Decompress.cs +++ b/src/libraries/System.IO.Compression.Brotli/src/System/IO/Compression/dec/BrotliStream.Decompress.cs @@ -133,7 +133,8 @@ namespace System.IO.Compression _bufferOffset = 0; int numRead = 0; - while (_bufferCount < _buffer.Length && ((numRead = await _stream.ReadAsync(new Memory(_buffer, _bufferCount, _buffer.Length - _bufferCount)).ConfigureAwait(false)) > 0)) + while (_bufferCount < _buffer.Length && + ((numRead = await _stream.ReadAsync(new Memory(_buffer, _bufferCount, _buffer.Length - _bufferCount), cancellationToken).ConfigureAwait(false)) > 0)) { _bufferCount += numRead; if (_bufferCount > _buffer.Length) diff --git a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFileStream.cs b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFileStream.cs index 7311503..54f0f83 100644 --- a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFileStream.cs +++ b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFileStream.cs @@ -236,7 +236,7 @@ namespace System.IO.IsolatedStorage public override Task FlushAsync(CancellationToken cancellationToken) { - return _fs.FlushAsync(); + return _fs.FlushAsync(cancellationToken); } public override void SetLength(long value) diff --git a/src/libraries/System.Net.Http.Json/src/System.Net.Http.Json.csproj b/src/libraries/System.Net.Http.Json/src/System.Net.Http.Json.csproj index 3440bd8..ee6e5c6 100644 --- a/src/libraries/System.Net.Http.Json/src/System.Net.Http.Json.csproj +++ b/src/libraries/System.Net.Http.Json/src/System.Net.Http.Json.csproj @@ -16,6 +16,7 @@ + @@ -24,6 +25,7 @@ + diff --git a/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.cs b/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.cs index b666f22..753c031 100644 --- a/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.cs +++ b/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; namespace System.Net.Http.Json { - public static class HttpContentJsonExtensions + public static partial class HttpContentJsonExtensions { public static Task ReadFromJsonAsync(this HttpContent content, Type type, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default) { @@ -32,16 +32,12 @@ namespace System.Net.Http.Json private static async Task ReadFromJsonAsyncCore(HttpContent content, Type type, Encoding? sourceEncoding, JsonSerializerOptions? options, CancellationToken cancellationToken) { - Stream contentStream = await content.ReadAsStreamAsync().ConfigureAwait(false); + Stream contentStream = await ReadHttpContentStreamAsync(content, cancellationToken).ConfigureAwait(false); // Wrap content stream into a transcoding stream that buffers the data transcoded from the sourceEncoding to utf-8. if (sourceEncoding != null && sourceEncoding != Encoding.UTF8) { -#if NETCOREAPP - contentStream = Encoding.CreateTranscodingStream(contentStream, innerStreamEncoding: sourceEncoding, outerStreamEncoding: Encoding.UTF8); -#else - contentStream = new TranscodingReadStream(contentStream, sourceEncoding); -#endif + contentStream = GetTranscodingStream(contentStream, sourceEncoding); } using (contentStream) @@ -52,16 +48,12 @@ namespace System.Net.Http.Json private static async Task ReadFromJsonAsyncCore(HttpContent content, Encoding? sourceEncoding, JsonSerializerOptions? options, CancellationToken cancellationToken) { - Stream contentStream = await content.ReadAsStreamAsync().ConfigureAwait(false); + Stream contentStream = await ReadHttpContentStreamAsync(content, cancellationToken).ConfigureAwait(false); // Wrap content stream into a transcoding stream that buffers the data transcoded from the sourceEncoding to utf-8. if (sourceEncoding != null && sourceEncoding != Encoding.UTF8) { -#if NETCOREAPP - contentStream = Encoding.CreateTranscodingStream(contentStream, innerStreamEncoding: sourceEncoding, outerStreamEncoding: Encoding.UTF8); -#else - contentStream = new TranscodingReadStream(contentStream, sourceEncoding); -#endif + contentStream = GetTranscodingStream(contentStream, sourceEncoding); } using (contentStream) diff --git a/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.netcoreapp.cs b/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.netcoreapp.cs new file mode 100644 index 0000000..0abdbc9 --- /dev/null +++ b/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.netcoreapp.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.IO; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace System.Net.Http.Json +{ + public static partial class HttpContentJsonExtensions + { + private static Task ReadHttpContentStreamAsync(HttpContent content, CancellationToken cancellationToken) + { + return content.ReadAsStreamAsync(cancellationToken); + } + + private static Stream GetTranscodingStream(Stream contentStream, Encoding sourceEncoding) + { + return Encoding.CreateTranscodingStream(contentStream, innerStreamEncoding: sourceEncoding, outerStreamEncoding: Encoding.UTF8); + } + } +} diff --git a/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.netstandard.cs b/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.netstandard.cs new file mode 100644 index 0000000..4b64d05 --- /dev/null +++ b/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.netstandard.cs @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.IO; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace System.Net.Http.Json +{ + public static partial class HttpContentJsonExtensions + { + private static Task ReadHttpContentStreamAsync(HttpContent content, CancellationToken cancellationToken) + { + // The ReadAsStreamAsync overload that takes a cancellationToken is not available in .NET Standard + return content.ReadAsStreamAsync(); + } + + private static Stream GetTranscodingStream(Stream contentStream, Encoding sourceEncoding) + { + return new TranscodingReadStream(contentStream, sourceEncoding); + } + } +} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs b/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs index eb4a75f..eb57732 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs @@ -145,11 +145,11 @@ namespace System.Net.Http { if (request.Content is StringContent) { - requestObject.SetObjectProperty("body", await request.Content.ReadAsStringAsync().ConfigureAwait(continueOnCapturedContext: true)); + requestObject.SetObjectProperty("body", await request.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext: true)); } else { - using (Uint8Array uint8Buffer = Uint8Array.From(await request.Content.ReadAsByteArrayAsync().ConfigureAwait(continueOnCapturedContext: true))) + using (Uint8Array uint8Buffer = Uint8Array.From(await request.Content.ReadAsByteArrayAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext: true))) { requestObject.SetObjectProperty("body", uint8Buffer); } diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/MessageProcessingHandler.cs b/src/libraries/System.Net.Http/src/System/Net/Http/MessageProcessingHandler.cs index 8455d6f..dff8ab9 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/MessageProcessingHandler.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/MessageProcessingHandler.cs @@ -77,7 +77,7 @@ namespace System.Net.Http if (task.IsCanceled) { - sendState.TrySetCanceled(); + sendState.TrySetCanceled(token); return; } diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/MultipartContent.cs b/src/libraries/System.Net.Http/src/System/Net/Http/MultipartContent.cs index 458591f..4f1a1dd 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/MultipartContent.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/MultipartContent.cs @@ -280,7 +280,7 @@ namespace System.Net.Http } else { - readStream = nestedContent.ReadAsStream(); + readStream = nestedContent.ReadAsStream(cancellationToken); } // Cannot be null, at least an empty stream is necessary. readStream ??= new MemoryStream(); @@ -292,8 +292,10 @@ namespace System.Net.Http // we fall back to the base behavior. We don't dispose of the streams already obtained // as we don't necessarily own them yet. +#pragma warning disable CA2016 // Do not pass a cancellationToken to base.CreateContentReadStreamAsync() as it would trigger an infinite loop => StackOverflow return async ? await base.CreateContentReadStreamAsync().ConfigureAwait(false) : base.CreateContentReadStream(cancellationToken); +#pragma warning restore CA2016 } streams[streamIndex++] = readStream; } diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/DecompressionHandler.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/DecompressionHandler.cs index 2fcd31d..5bac88a 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/DecompressionHandler.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/DecompressionHandler.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.IO; using System.IO.Compression; using System.Net.Http.Headers; +using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -164,7 +165,7 @@ namespace System.Net.Http } else { - originalStream = _originalContent.ReadAsStream(); + originalStream = _originalContent.ReadAsStream(cancellationToken); } return GetDecompressedStream(originalStream); } diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs index ce54561..52f2363 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs @@ -145,7 +145,7 @@ namespace System.Net.Http { // Flush to ensure we get a response. // TODO: MsQuic may not need any flushing. - await _stream.FlushAsync().ConfigureAwait(false); + await _stream.FlushAsync(cancellationToken).ConfigureAwait(false); } else { diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketBase.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketBase.cs index 2d72978..e0ea87b 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketBase.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketBase.cs @@ -1591,7 +1591,7 @@ namespace System.Net.WebSockets WebSocketProtocolComponent.WebSocketCompleteAction(_webSocket, actionContext, 0); AsyncOperationCompleted = true; ReleaseLock(_webSocket.SessionHandle, ref sessionHandleLockTaken); - await _webSocket._innerStream.FlushAsync().SuppressContextFlow(); + await _webSocket._innerStream.FlushAsync(cancellationToken).SuppressContextFlow(); Monitor.Enter(_webSocket.SessionHandle, ref sessionHandleLockTaken); break; case WebSocketProtocolComponent.Action.SendToNetwork: diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.Unix.cs index 46deea5..1adc483 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.Unix.cs @@ -684,7 +684,7 @@ namespace System.IO } // Serialize operations using the semaphore. - Task waitTask = _asyncState.WaitAsync(); + Task waitTask = _asyncState.WaitAsync(cancellationToken); // If we got ownership immediately, and if there's enough space in our buffer // to buffer the entire write request, then do so and we're done. diff --git a/src/libraries/System.Threading.Channels/src/System/Threading/Channels/SingleConsumerUnboundedChannel.cs b/src/libraries/System.Threading.Channels/src/System/Threading/Channels/SingleConsumerUnboundedChannel.cs index 015d7f8..50398e8 100644 --- a/src/libraries/System.Threading.Channels/src/System/Threading/Channels/SingleConsumerUnboundedChannel.cs +++ b/src/libraries/System.Threading.Channels/src/System/Threading/Channels/SingleConsumerUnboundedChannel.cs @@ -114,7 +114,7 @@ namespace System.Threading.Channels parent._blockedReader = newBlockedReader; } - oldBlockedReader?.TrySetCanceled(); + oldBlockedReader?.TrySetCanceled(default); return newBlockedReader.ValueTaskOfT; } @@ -183,7 +183,7 @@ namespace System.Threading.Channels parent._waitingReader = newWaitingReader; } - oldWaitingReader?.TrySetCanceled(); + oldWaitingReader?.TrySetCanceled(default); return newWaitingReader.ValueTaskOfT; } -- 2.7.4