Skip to content

System.InvalidOperationException ("Concurrent reads or writes are not supported.") #170

Description

@Xhanti

Hi,

When trying to use the IConnectionFactory in parallel like this:

var serviceCollection = new ServiceCollection();
var serviceProvider = serviceCollection.BuildServiceProvider();
var client = new ClientBuilder(serviceProvider)
                       .UseSockets()                           
                       .Build();
await using (var connection = await client.ConnectAsync(new IPEndPoint(IPAddress.Loopback, 5000)))
{
    await Parallel.ForAsync(0, 10, options, async (i, ct) =>
    {
        var request = new HttpRequestMessage(HttpMethod.Get, "/");
        request.Headers.Host = "localhost";
        var httpProtocol = new HttpClientProtocol(connection);
        var response = await httpProtocol.SendAsync(request);
    });
}

I get System.InvalidOperationException saying "Concurrent reads or writes are not supported."
Digging around I see this is inside system.io.pipelines:

   at Bedrock.Framework.Protocols.HttpClientProtocol.<SendAsync>d__4.MoveNext()
   at Bedrock.Framework.Protocols.HttpClientProtocol.<SendAsync>d__4.MoveNext()
   at Bedrock.Framework.Protocols.HttpClientProtocol.<SendAsync>d__4.MoveNext()
   at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result) in System.IO.Pipelines\Pipe.cs:line 901
   at System.IO.Pipelines.Pipe.GetReadAsyncResult() in System.IO.Pipelines\Pipe.cs:line 885
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
   at Bedrock.Framework.Protocols.ProtocolReader.<ContinueDoAsyncRead>d__14`1.MoveNext()
   at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
   at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
   at Program.<>c__DisplayClass0_0.<<<Main>$>b__0>d.MoveNext() in C:\Working\Raikiri\Raikiri\Program.cs:line 41
   at Bedrock.Framework.Protocols.HttpClientProtocol.<SendAsync>d__4.MoveNext()
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
--- End of stack trace from previous location ---
   at Bedrock.Framework.Protocols.HttpClientProtocol.<SendAsync>d__4.MoveNext()
   at System.Threading.Tasks.Parallel.<>c__49`1.<<ForAsync>b__49_0>d.MoveNext()
   at System.Threading.Tasks.Parallel.<>c__49`1.<<ForAsync>b__49_0>d.MoveNext()
image

Is this expected behavior?
For a bit of colour, I'm experimenting with using this framework to put something like https://github.com/codesenberg/bombardier together in .NET

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions