Skip to content

A cancellation doesn't work in some cases and app hangs. #351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Docker.DotNet/DockerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ internal DockerClient(DockerClientConfiguration configuration, Version requested
// NamedPipeClientStream handles file not found by polling until the server arrives. Use a short
// timeout so that the user doesn't get stuck waiting for a dockerd instance that is not running.
var timeout = 100; // 100ms
var stream = new NamedPipeClientStream(serverName, pipeName);
var stream = new NamedPipeClientStream(
serverName,
pipeName,
PipeDirection.InOut,
PipeOptions.Asynchronous);
var dockerStream = new DockerPipeStream(stream);

#if NET45
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ private async Task EnsureBufferedAsync(CancellationToken cancel)
{
_bufferOffset = 0;
_bufferCount = await _inner.ReadAsync(_buffer, _bufferOffset, _buffer.Length, cancel).ConfigureAwait(false);

ThrowIfDisposed();

if (_bufferCount == 0)
{
throw new IOException("Unexpected end of stream");
Expand Down
11 changes: 11 additions & 0 deletions test/Docker.DotNet.Tests/ISystemOperations.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ public async Task MonitorEventsAsync_Succeeds()
await _client.Images.DeleteImageAsync($"{repository}:{tag}", new ImageDeleteParameters());
}

[Fact]
public async Task MonitorEventsAsync_EmptyContainersList_CanBeCancelled()
{
var cts = new CancellationTokenSource();
cts.CancelAfter(1000);

var task = _client.System.MonitorEventsAsync(new ContainerEventsParameters(), new Progress(), cts.Token);

await task;
}

class Progress : IProgress<JSONMessage>
{
internal Action<JSONMessage> _onCalled;
Expand Down