Skip to content

Commit 8876a33

Browse files
author
Ben de Bruyn
committed
#375 Response stream corruption when a request is cancelled
1 parent f44e6ea commit 8876a33

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Docker.DotNet/Endpoints/StreamUtil.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ internal static async Task MonitorStreamAsync(Task<Stream> streamTask, DockerCli
1414
using (var stream = await streamTask)
1515
{
1616
// ReadLineAsync must be cancelled by closing the whole stream.
17-
using (cancel.Register(() => stream.Dispose()))
17+
//using (cancel.Register(() => stream.Dispose()))
1818
{
1919
using (var reader = new StreamReader(stream, new UTF8Encoding(false)))
2020
{
2121
string line;
22-
while ((line = await reader.ReadLineAsync()) != null)
22+
while ((line = await reader.ReadLineAsync()) != null && !cancel.IsCancellationRequested)
2323
{
2424
progress.Report(line);
2525
}
@@ -33,14 +33,14 @@ internal static async Task MonitorStreamForMessagesAsync<T>(Task<Stream> streamT
3333
using (var stream = await streamTask)
3434
{
3535
// ReadLineAsync must be cancelled by closing the whole stream.
36-
using (cancel.Register(() => stream.Dispose()))
36+
//using (cancel.Register(() => stream.Dispose()))
3737
{
3838
using (var reader = new StreamReader(stream, new UTF8Encoding(false)))
3939
{
4040
string line;
4141
try
4242
{
43-
while ((line = await reader.ReadLineAsync()) != null)
43+
while ((line = await reader.ReadLineAsync()) != null && !cancel.IsCancellationRequested)
4444
{
4545
var prog = client.JsonSerializer.DeserializeObject<T>(line);
4646
if (prog == null) continue;

0 commit comments

Comments
 (0)