-
Notifications
You must be signed in to change notification settings - Fork 382
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
cannot hijack chunked or content length stream #554
Comments
Hi, I'd like to also mention I am receiving this exception. My case is a bit different:
I asked a colleague of mine who still had Docker Desktop installed, to try the example unit test they dotnet-testcontainers project supplies, and it works. Unfortunately using Docker Desktop for Windows is not an option due to licensing. Some debugging information that may help: This is the code in question that throws the exception.
In my use case, |
I am also having the same issue using .net 6.0 C# |
So I dug into this a little bit, and it seems the interaction with the Api when Rancher Desktop is being used always returns a ChunkedStream. If I drop the HTTP version from 1.1 to 1.0, it returns the BufferedReadStream, which seems to work fine... //request.Version = new Version(1, 1); Are there any particular features needed from 1.1 or is this an ok workaround? |
Hi, first time submitting a PR, no doubt I will need to revise it. In order to "solve" this issue without breaking everything else I have added the abiility to specify the Http Version in the Docker client configuration. If there are any issues or changes I need to make, please feel free to let me know - the PR is this one: |
I've done a couple of tests and I guess the current implementation does not handle chunked streams (HTTP 1.1) very well. Looking into the Docker Engine API documentation, I assume chunked transfer encoding should be supported. diff --git a/src/Docker.DotNet/DockerClient.cs b/src/Docker.DotNet/DockerClient.cs
index 30406dd..57fbcc1 100644
--- a/src/Docker.DotNet/DockerClient.cs
+++ b/src/Docker.DotNet/DockerClient.cs
@@ -333,6 +333,10 @@ namespace Docker.DotNet
throw new NotSupportedException("message handler does not support hijacked streams");
}
+ var stream = await content.ReadAsStreamAsync()
+ .ConfigureAwait(false);
+ return (WriteClosableStream)stream;
+
return content.HijackStream();
}
diff --git a/src/Docker.DotNet/Microsoft.Net.Http.Client/ChunkedReadStream.cs b/src/Docker.DotNet/Microsoft.Net.Http.Client/ChunkedReadStream.cs
index 1076804..9dabcb2 100644
--- a/src/Docker.DotNet/Microsoft.Net.Http.Client/ChunkedReadStream.cs
+++ b/src/Docker.DotNet/Microsoft.Net.Http.Client/ChunkedReadStream.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Microsoft.Net.Http.Client
{
- internal class ChunkedReadStream : Stream
+ internal class ChunkedReadStream : WriteClosableStream
{
private readonly BufferedReadStream _inner;
private long _chunkBytesRemaining;
@@ -176,5 +176,13 @@ namespace Microsoft.Net.Http.Client
{
throw new NotSupportedException();
}
+
+ public override bool CanCloseWrite
+ => _inner.CanCloseWrite;
+
+ public override void CloseWrite()
+ {
+ _inner.CloseWrite();
+ }
}
} With this patch, I was able to use the broken API calls like |
It's broken now for Docker Desktop for Windows (4.10.0) too. The patch above fixes the issue for 4.10.0 too. |
Fyi in case it helps, we have hit the same issue on a mac Monterey 12.4 environment. Docker was installed via docker desktop (version 4.10.0), we'll try to downgrade (edit: downgrading to 4.9.1 makes the error go away).
|
@jstarks can you help here? |
Getting this bug as well. We're using a library that internally uses Docker.DotNet quite heavily for integration testing. Hoping for a quick fix. |
Hey folks! The fix is in and released here: https://www.nuget.org/packages/Docker.DotNet/3.125.10 |
@HofmeisterAn @galvesribeiro Thanks for the fix 👍 It also solved the issue we run into in our case. In our use-case we try to execute some bash commands and want to read the output of the commands as well. Like mentioned this works with Docker Desktop 4.9.1. A difference which I noticed is that the property Should I create a new Issue for this case? Or do you think it is related? |
Yeah please create a separated issue and share it there. I'm going to close this as the PR was merged and the original issue is fixed. Thanks! |
I would prefer a new issue. Did you check the Docker.DotNet/src/Docker.DotNet/Microsoft.Net.Http.Client/ChunkedReadStream.cs Lines 36 to 39 in f587486
|
Hello, why this module https://github.com/dotnet/Docker.DotNet/blob/master/src/Docker.DotNet/Microsoft.Net.Http.Client/HttpConnectionResponseContent.cs said me - "cannot hijack chunked or content length stream".
This is my attempt to attach to container
I'm don't sure that this approach is right, I need to realize simple operation
But receive this result
The text was updated successfully, but these errors were encountered: