Repository navigation
Closed
Labels
Description
This requires running go test directly on macos (not dagger-in-dagger):
sipsma@Eriks-MBP-2 dagger % go test -v -count=1 -run TestContainerWithUnixSocket $(pwd)/core/integration
=== RUN TestContainerWithUnixSocket
#1 resolve image config for docker.io/library/golang:1.18.2-alpine
#1 DONE 0.6s
#2 mkfile /main.go
#2 CACHED
#3 mkdir /meta
#3 CACHED
#4 docker-image://docker.io/library/golang:1.18.2-alpine
#4 resolve docker.io/library/golang:1.18.2-alpine
#4 resolve docker.io/library/golang:1.18.2-alpine 0.2s done
#4 CACHED
#5 go run /src/main.go /tmp/test.sock hello
#5 0.199 panic: EOF
#5 0.199
#5 0.199 goroutine 1 [running]:
#5 0.199 main.main()
#5 0.199 /src/main.go:31 +0x274
container_test.go:2575:
Error Trace: /Users/sipsma/dagger/core/integration/container_test.go:2575
Error: Received unexpected error:
input:1: container.from.withMountedFile.withUnixSocket.withExec.stdout process "go run /src/main.go /tmp/test.sock hello" did not complete successfully: exit code: 1
Please visit https://dagger.io/help#go for troubleshooting guidance.
Test: TestContainerWithUnixSocket
--- FAIL: TestContainerWithUnixSocket (2.08s)
FAIL
FAIL github.com/dagger/dagger/core/integration 2.248s
FAILThe same test passes when run directly on Linux.
Notably, the container only fails once it tries to read from the unix socket (this line), it can connect and write to it successfully, so it's not completely broken.
Also, when I instead run this test case on macos directly, it passes:
func TestContainerWithUnixSocket(t *testing.T) {
ctx := context.Background()
c, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
require.NoError(t, err)
dockerSock := c.Host().UnixSocket("/var/run/docker.sock")
out, err := c.Container().
From("docker").
WithUnixSocket("/var/run/docker.sock", dockerSock).
WithExec([]string{"docker", "ps", "-a"}).
Stdout(ctx)
require.NoError(t, err)
require.Contains(t, out, "CONTAINER ID")
}Based on that my best guess is that there's some subtle difference in unix socket behavior on macos vs linux and the loop in the original test case of accept, copy, close doesn't quite work for some reason. And then it works using the docker.sock because docker probably has code to properly handle the difference.
However, that's very much pure speculation, needs investigation.
Reacted by George MacRorie
Activity
sipsma commentedon Dec 1, 2022
cc @vito
sipsma commentedon Dec 1, 2022
Also @vito, I just remembered you also added that
TestGitSSHAuthSocktest case. That passes totally fine on my mac w/out modification, so I suppose that increases the liklihood of it being specific to that other test case somehowsipsma commentedon Dec 3, 2022
(posting a message already sent on discord earlier)
I am not sure whether this is actually related or not, may be a total red herring, but it seems somewhat similar: I found that provisioning of the engine-session binary inside a dagger exec w/ the host's docker sock mounted doesn't work. Whenever an SDK runs the provisioning, the
docker run --rm --entrypoint /bin/cat <image> /usr/bin/dagger-engine-sessionsucceeds (exits w/ code 0) but the actual binary is always an empty file.I also verified that if I run an exec where I do the same command from a shell (with
> /tmp/engine-session) I get the same behavior.The reason this seems similar is that it could be explain by the docker cli getting an unexpected early EOF while reading from the docker unix socket, which is exactly the failure seen in the test case mentioned here.
This isn't a huge deal because we plan on changing the provisioning to download the CLI in the very near future, but still kind of odd. Again, could be completely unrelated to this issue, but mentioning in case it gives any debugging clues.
GeorgeMac commentedon Dec 16, 2022
Just chiming in to say that I have experienced this in a project I work on 👋
We have a test suite using
testcontainers-go. I was experimenting with dagger for our CI pipeline.When I attempt to run our entire test suite, it fails when starting containers.
I have used this feature (
WithUnixSocket) in an attempt to get docker connectivity into my test.However, ultimately, this fails with
failed to create container(I think this is coming out of testcontainers).That said, I see the container starting when I do
docker ps.As you said @sipsma, it appears to be writing something, but down a one-way street.
Unlikely this is useful, but this is where I am experimenting https://github.com/flipt-io/flipt/compare/gm/dagger-experiment?expand=1#diff-9eb02ca4f9553591bbf647feac8cbf2a35edcb53e9d9c62dddd87689d6e699e4R9-R16
Oh, I am using Docker Desktop on MacOS.
jpadams commentedon Dec 21, 2022
Seeing this issue on Mac M1
This works:
"stdout": "Linux\n"but these both work and produce expected output:
these both seem to run, but don't produce any output (watch out for caching on subsequent runs with first one, change the sleep interval as needed to re-run):
sipsma commentedon Dec 21, 2022
I did a bit more debugging by modifying the socket proxy code to print all the contents it reads+writes on the host side socket.
From that I also managed to actually get the output to work if I made it so
Closecalls to that socket are ignored. I then added a stack trace print to that close call and found that it was getting called here: https://github.com/moby/buildkit/blob/c0e38e194c276a6e619e17a5ee7158e5bf55f5bf/session/sshforward/copy.go#L23Code with all the debug prints and ignore of close: sipsma@05f6a8e
The fact that if I ignore the Close calls everything works as expected suggests to me that the err returned by
stream.RecvMsgis safe to ignore in this case, so I think this might require a fix upstream in buildkit.I need to dig a bit more to understand why
stream.RecvMsggets an error first though.My initial hunch is that after the HTTP upgrade (see debug logs below), then client-side (docker cli running in container) is closing its side of the connection to indicate it will only be reading from here on out, not writing. But then that gets converted into a generic
EOFin the grpc stream and the code presumes the whole stream is closed even though it just means the client won't be writing anymore data.Used a slightly modified version of @jpadams snippets (thanks!):
Output when running with the debug output and ignore of close:
cc @vito @marcosnils
sipsma commentedon Dec 21, 2022
Found the relevant grpc docs, confirmed that the client can close the send side but still want to use the recv side. Opened a fix upstream here: moby/buildkit#3431
marcosnils commentedon Dec 21, 2022
🎉 great!
sipsma commentedon Jan 4, 2023
This will be picked up and fixed when we update to the new buildkit release: #4293
sipsma commentedon Jan 4, 2023
That upstream fix wasn't in v0.11-rc3 so still need to wait for the official release or another rc, but in the meantime I double checked and confirmed that the
docker runcase works now on macos when using buildkit from my upstream commit.That's good because it is an actual real world use case we care about and it works now. However when I try the test case this issue was originally created for, I am still getting the same EOF as before sadly.
I dug in a bit and it seems to be a completely different issue even though it seemed similar to the docker run case. I found that on macos we never even make it past this line where the macos buildkit client is trying to connect to the locally created unix socket. We also never make it past the accept call in the actual test case code (though we do successfully make it past the listen call outside the goroutine).
This makes me suspect once again that there's just something about macos that is different than linux in terms of how you setup listening on a unix socket. I have other higher priority things to get to so cutting this off here for the moment since it seems the real-world use case is working now at least.