MultiplexedStream concurrent read/write deadlock
- Dominant language
- C#
- Stars
- 2.4k
- Forks
- 416
- PR merge metrics
- No merged PRs in 30d
Description
**Output of `dotnet --info`:**
.NET Core SDK (reflecting any global.json):
Version: 2.2.106
Commit: aa79b139a8
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17763
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.2.106\
Host (useful for support):
Version: 2.2.4
Commit: f95848e524
.NET Core SDKs installed:
2.0.0 [C:\Program Files\dotnet\sdk]
2.1.104 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.500 [C:\Program Files\dotnet\sdk]
2.1.505 [C:\Program Files\dotnet\sdk]
2.2.106 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
**What version of Docker.DotNet?:**
3.125.2
**Steps to reproduce the issue:**
1.Create the container exec session:
`var execCreateRes = await dockerClient.Containers.ExecCreateContainerAsync(container.ID, execCreateParams, cancellationToken);`
2.Start and attach to the container exec session:
`var containerStream = await dockerClient.Containers.StartAndAttachContainerExecAsync(execCreateRes.ID, true, cancellationToken);`
3.Create two tasks, one to read from the container stream, another to write to the container stream:
```
var taskRead = Task.Run(() =>
{
while (//loopCondition)
{
var buffer = new byte[1024 * 4];
MultiplexedStream.ReadResult containerStreamReadResult = await containerStream.ReadOutputAsync(buffer, 0, buffer.Length, CancellationToken.None);
// write to my destination stream (websocket)
}
});
var taskWrite = Task.Run(() =>
{
while (//loopCondition)
{
var buffer = new byte[1024 * 4];
// read from my destination stream (websocket) into buffer
await containerStream.WriteAsync(buffer, 0, destinationStreamReadResult.Count, CancellationToken.None);
}
});
```
**What actually happened?:**
At first the read task executes and sends the initial bytes to the destination websocket, then goes to read from the stream again and awaits it. Then the destination websocket sends some content and the write task reads that and goes to write it into the container stream. This write call then blocks indefinitely.
This does not happend when running in a single thread way where we do all 4 operations sequentially in a loop:
read from destination stream
send to container stream
read from container stream
send to destination stream
**What did you expect to happen?:**
The write call should finish and the pending read call should pick up the response to whatever the write call wrote. This is the behavior that websockets have and I would expect the multiplexed stream should be able to handle this as well.
**Additional information:**
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.