Skip to content

Commit

Permalink
make Quic AcceptStreamAsync concurrent safe (#56768)
Browse files Browse the repository at this point in the history
* make AcceptStreamAsync concurrent safe

* feedback from review
  • Loading branch information
wfurt committed Aug 4, 2021
1 parent 804f8e4 commit c082af3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Expand Up @@ -74,7 +74,6 @@ internal sealed class State
// Backlog limit is managed by MsQuic so it can be unbounded here.
public readonly Channel<MsQuicStream> AcceptQueue = Channel.CreateUnbounded<MsQuicStream>(new UnboundedChannelOptions()
{
SingleReader = true,
SingleWriter = true,
});

Expand Down
Expand Up @@ -159,6 +159,35 @@ public async Task MultipleStreamsOnSingleConnection()
);
}

[Fact]
public async Task MultipleConcurrentStreamsOnSingleConnection()
{
const int count = 100;
Task[] tasks = new Task[count];

(QuicConnection clientConnection, QuicConnection serverConnection) = await CreateConnectedQuicConnection();
using (clientConnection)
using (serverConnection)
{
for (int i = 0; i < count; i++)
{
tasks[i] = MakeStreams(clientConnection, serverConnection);
}
await tasks.WhenAllOrAnyFailed(PassingTestTimeoutMilliseconds);
}

static async Task MakeStreams(QuicConnection clientConnection, QuicConnection serverConnection)
{
byte[] buffer = new byte[64];
QuicStream clientStream = clientConnection.OpenBidirectionalStream();
ValueTask writeTask = clientStream.WriteAsync(Encoding.UTF8.GetBytes("PING"), endStream: true);
ValueTask<QuicStream> acceptTask = serverConnection.AcceptStreamAsync();
await new Task[] { writeTask.AsTask(), acceptTask.AsTask()}.WhenAllOrAnyFailed(PassingTestTimeoutMilliseconds);
QuicStream serverStream = acceptTask.Result;
await serverStream.ReadAsync(buffer);
}
}

[Fact]
public async Task GetStreamIdWithoutStartWorks()
{
Expand Down

0 comments on commit c082af3

Please sign in to comment.