Skip to content

[QUIC] Throw on write after closed writing side#128494

Open
ManickaP wants to merge 2 commits into
dotnet:mainfrom
ManickaP:quic-write
Open

[QUIC] Throw on write after closed writing side#128494
ManickaP wants to merge 2 commits into
dotnet:mainfrom
ManickaP:quic-write

Conversation

@ManickaP
Copy link
Copy Markdown
Member

Fixes #121619

Copilot AI review requested due to automatic review settings May 22, 2026 16:51
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

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

@ManickaP ManickaP requested a review from a team May 22, 2026 16:52
Copy link
Copy Markdown
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 adjusts System.Net.Quic.QuicStream.WriteAsync to throw when callers attempt to write after the stream’s writing side has been gracefully completed, and adds a functional regression test to lock in the behavior. It also includes minor doc-comment grammar fixes and adds a new localized error string.

Changes:

  • Update QuicStream.WriteAsync to throw InvalidOperationException when a previously returned write ValueTask is already completed successfully (intended to represent a closed writing side).
  • Add a new functional test validating WriteAsync throws after CompleteWrites() + WritesClosed.
  • Fix small “is/if” typos in internal task source XML docs and add a new resx string for the new exception message.

Reviewed changes

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

Show a summary per file
File Description
src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.cs Changes WriteAsync behavior for post-write-closure calls to throw instead of returning a successful completed ValueTask.
src/libraries/System.Net.Quic/tests/FunctionalTests/QuicStreamTests.cs Adds regression coverage for writing after the writing side has closed.
src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/ValueTaskSource.cs Fixes XML doc grammar (“is” → “if”).
src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/ResettableValueTaskSource.cs Fixes XML doc grammar (“is” → “if”).
src/libraries/System.Net.Quic/src/Resources/Strings.resx Adds a new localized string for the new InvalidOperationException message.

Comment on lines +423 to +425
// It doesn't matter that we throw away the valueTask here, it doesn't need to be reset anymore.
// The writing side is closed, the task is completed, and it will never get past this condition.
return valueTask.IsCompletedSuccessfully ?
Comment on lines +800 to +802
// These both should throw the same exception.
await Assert.ThrowsAsync<InvalidOperationException>(async () => await clientStream.WriteAsync(new byte[0], false));
await Assert.ThrowsAsync<InvalidOperationException>(async () => await clientStream.WriteAsync(new byte[0], false));
<value>Authentication failed because the remote party sent a TLS alert: '{0}'.</value>
</data>
<data name="net_writecompleted_invalidcall" xml:space="preserve">
<value>This method may not be called when writing side was already completed.</value>
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.

QuicStream writes do not throw after the stream is closed

2 participants