Skip to content

fix(agent/agentcontainers): handle race between docker ps and docker inspect #17447

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

Merged
merged 5 commits into from
Apr 17, 2025

Conversation

johnstcn
Copy link
Member

Comment on lines 231 to 243
// DockerCLILister is a ContainerLister that lists containers using the docker CLI
type DockerCLILister struct {
execer agentexec.Execer
}

var _ Lister = &DockerCLILister{}

func NewDocker(execer agentexec.Execer, opts ...func(*DockerCLILister)) Lister {
return &DockerCLILister{
execer: agentexec.DefaultExecer,
}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review: just moved down a bit closer to the method definitions

Comment on lines 233 to 238
if runtime.GOOS != "linux" {
t.Skip("Skipping on non-Linux OS")
}
if _, err := exec.LookPath("devcontainer"); err != nil {
t.Fatal("this test requires the devcontainer CLI: npm install -g @devcontainers/cli")
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review: I didn't look too closely into what was actually going on here, but I suspect it's related to path differences between the host and the Docker VM on MacOS/Windows.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've run this on macOS as well, so IMO we could allow that, but agree that we need to verify the devcontainer CLI here, good add 👍🏻

Comment on lines 233 to 238
if runtime.GOOS != "linux" {
t.Skip("Skipping on non-Linux OS")
}
if _, err := exec.LookPath("devcontainer"); err != nil {
t.Fatal("this test requires the devcontainer CLI: npm install -g @devcontainers/cli")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've run this on macOS as well, so IMO we could allow that, but agree that we need to verify the devcontainer CLI here, good add 👍🏻

@johnstcn
Copy link
Member Author

I've run this on macOS as well, so IMO we could allow that

Interesting, so "works on my machine" 🤔 I tried to figure out what the root cause was on my end, but the error returned by devcontainer-cli is not terribly useful:

          	Error Trace:	/Users/cian/src/coder/coder/agent/agentcontainers/devcontainercli_test.go:256
            	Error:      	Received unexpected error:
            	            	exit status 1
            	            	devcontainer up failed: error (description: An error occurred setting up the container., message: Command failed: docker run --sig-proxy=false -a STDOUT -a STDERR --mount type=bind,source=/tmp/nix-shell.56XzZC/TestDockerDevcontainerCLIContainerLifecycle1281021640/001,target=/workspaces/001,consistency=cached -l devcontainer.local_folder=/tmp/nix-shell.56XzZC/TestDockerDevcontainerCLIContainerLifecycle1281021640/001 -l devcontainer.config_file=/tmp/nix-shell.56XzZC/TestDockerDevcontainerCLIContainerLifecycle1281021640/001/.devcontainer/devcontainer.json -e TEST_CONTAINER=true --label com.coder.test=devcontainercli --entrypoint /bin/sh -l devcontainer.metadata=[{"containerEnv":{"TEST_CONTAINER":"true"}}] alpine:latest -c echo Container started

@johnstcn johnstcn requested a review from mafredri April 17, 2025 12:01
@mafredri
Copy link
Member

@johnstcn interesting, here's me on macOS:

❯ CODER_TEST_USE_DOCKER=1 go test ./agent/agentcontainers -count=1
ok      github.com/coder/coder/v2/agent/agentcontainers 4.978s

Perhaps it's a Nix issue?

@johnstcn
Copy link
Member Author

@johnstcn interesting, here's me on macOS:

❯ CODER_TEST_USE_DOCKER=1 go test ./agent/agentcontainers -count=1
ok      github.com/coder/coder/v2/agent/agentcontainers 4.978s

Perhaps it's a Nix issue?

It happens outside the nix environment as well, strangely enough 🤷

return stdout, stderr, err
if err != nil && bytes.Contains(stderr, []byte("No such object:")) {
// This can happen if a container is deleted between the time we check for its existence and the time we inspect it.
return stdout, stderr, nil
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Nit: Ideally I'd like to avoid disconnected err handling (code slipping in between err := and return err due to whitespace), but I'll settle for removing the newline.

(Preferable, but not required: return explicitly either nil or err from if err != nil-block.)

@mafredri
Copy link
Member

It happens outside the nix environment as well, strangely enough 🤷

Then it's probably a matter of your Docker configuration, you might have to add /tmp to allowed paths.

@johnstcn johnstcn merged commit 6a79965 into main Apr 17, 2025
34 checks passed
@johnstcn johnstcn deleted the cj/flake/exp-rpty-container branch April 17, 2025 12:50
@github-actions github-actions bot locked and limited conversation to collaborators Apr 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flake: TestExpRpty/Container
2 participants