Skip to content

[QUIC] QuicStreamAbortedException sometimes is not thrown #53530

@CarnaViire

Description

@CarnaViire

I found this while investigating pre-cancelled writes for #32077

This might be a result of a race condition, because I can see exception being set to ResettableCompletionSource, but it is not propagated to Read call.

It reproduces for me on this

        [Fact]
        public async Task StreamAbortedWithoutWriting_ReadThrows()
        {
            long expectedErrorCode = 1234;

            await RunClientServer(
                clientFunction: async connection =>
                {
                    await using QuicStream stream = connection.OpenUnidirectionalStream();
                    stream.AbortWrite(expectedErrorCode);

                    await stream.ShutdownCompleted();
                },
                serverFunction: async connection =>
                {
                    await using QuicStream stream = await connection.AcceptStreamAsync();

                    byte[] buffer = new byte[1];

                    // this assert fails (no exception was thrown)
                    QuicStreamAbortedException ex = await Assert.ThrowsAsync<QuicStreamAbortedException>(() => ReadAll(stream, buffer));
                    Assert.Equal(expectedErrorCode, ex.ErrorCode);

                    await stream.ShutdownCompleted();
                }
            );
        }

If I write anything to stream before aborting it, exception is thrown as expected.
I have just reproduced it after writing too.

I suspect it might be fixed by #52929 because @scalablecory mentioned fixing some race conditions for read state.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions