Skip to content

Conversation

@rzikm
Copy link
Member

@rzikm rzikm commented Nov 20, 2025

For stream which wrap another stream (SslStream, compression streams, crypto streams, ....), we can test if async methods are calling only async methods. This should root out cases where we may be mistakenly doing blocking IO calls as part of async stack.

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 20, 2025
@rzikm rzikm marked this pull request as ready for review November 25, 2025 12:22
Copilot AI review requested due to automatic review settings November 25, 2025 12:22
@rzikm rzikm added area-Meta and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Nov 25, 2025
@rzikm rzikm requested review from a team and stephentoub November 25, 2025 12:22
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-meta
See info in area-owners.md if you want to be subscribed.

Copilot finished reviewing on behalf of rzikm November 25, 2025 12:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enforces async-only methods in StreamConformanceTests to ensure that async operations in wrapper streams (SslStream, compression streams, crypto streams) don't perform blocking IO calls. The changes introduce an AsyncOnlyStream wrapper that throws when synchronous methods are called, and update tests to use async operations when testing async code paths.

Key changes:

  • Introduced AsyncOnlyStream wrapper to enforce async-only operations during testing
  • Updated test methods to use async disposal patterns and wrap streams appropriately based on async mode
  • Converted synchronous IO operations to async in SslStream tests to avoid blocking

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamConformanceTests.cs Converted sync Read/Write calls to async ReadAsync/WriteAsync to avoid blocking during TLS 1.3 handshake flush
src/libraries/Common/tests/StreamConformanceTests/System/IO/StreamConformanceTests.cs Added AsyncOnlyStream wrapper class, CreateWrappedStreamsAsync helper, IsAsync helper, updated test disposal patterns to use async, and added IAsyncDisposable to StreamPair

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

return _innerStream.DisposeAsync();
}

public override void Close() => _innerStream.Close();
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Close() method in AsyncOnlyStream may call synchronous Dispose() internally on the inner stream. This could result in blocking IO operations that this wrapper is designed to prevent. Consider throwing NotSupportedException for Close() similar to other sync methods, or override Close() to call Dispose(false) directly without calling the inner stream's Close(), since disposal is already handled in Dispose(bool) and DisposeAsync().

Suggested change
public override void Close() => _innerStream.Close();
public override void Close()
{
throw new NotSupportedException("Synchronous operations are not supported.");
}

Copilot uses AI. Check for mistakes.
if (_disposed) return;

_disposed = true;
_innerStream.Dispose();
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Dispose(bool) method unconditionally calls _innerStream.Dispose() even when disposing is false (finalizer path). The disposing parameter should be checked, and the inner stream should only be disposed when disposing is true. Additionally, calling _innerStream.Dispose() is a synchronous operation that could perform blocking IO, which contradicts the purpose of AsyncOnlyStream. Consider either: (1) not disposing the inner stream in synchronous Dispose and requiring callers to use DisposeAsync, or (2) checking the disposing parameter properly.

Suggested change
_innerStream.Dispose();
if (disposing)
{
_innerStream.Dispose();
}

Copilot uses AI. Check for mistakes.
{
if (_disposed) return default;

_disposed = true;
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DisposeAsync() method should call GC.SuppressFinalize(this) to prevent the finalizer from running after async disposal completes. This is a standard pattern for types implementing both IDisposable and IAsyncDisposable.

Suggested change
_disposed = true;
_disposed = true;
GC.SuppressFinalize(this);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant