Skip to content

fix: run nf-spawn's docker run via sudo, fixing exit-126 socket permission (#92) - #94

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/92-docker-socket-permission
Sep 5, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/92-docker-socket-permission

Conversation

@scttfrdmn

Copy link
Copy Markdown
Collaborator

Summary

Fixes #92 — every containerized process (container directive + executor = 'spawn') on a stock AMI failed immediately with exit 126 and this in .command.err:

docker: permission denied while trying to connect to the Docker daemon socket at
unix:///var/run/docker.sock: ... connect: permission denied.
  • Confirmed this is nf-spawn's own docker run (in SpawnTaskHandler.buildRunLine, src/main/groovy/io/nextflow/spawn/SpawnTaskHandler.groovy) — not Nextflow's own container-launch code, since the docker run never appears in .command.run, and docker { sudo = true } (which would only affect Nextflow's own docker calls) had no effect.
  • ensureDocker's setup script (buildSetupScript) installs Docker and starts the daemon, but never puts the task user in the docker group — and even if it tried to (usermod -aG docker), that wouldn't take effect in the same shell session, which is exactly what happens here: setup and the containerized task run in one continuous bash -lc invocation (no new login shell in between).
  • The fix: prefix the docker run invocation with sudo. This is the option the issue itself suggested and the one confirmed safe by checking the actual instance provisioning: spawn's own bootstrap grants the launched instance's login user passwordless sudo (NOPASSWD:ALL in /etc/sudoers.d/, in spawn's pkg/launcher/bootstrap.go) — the very same precondition nf-spawn's staging script already depends on for its sudo dnf install/sudo systemctl/sudo mkdir calls. sudo also matches how spawn's own task wrapper (pkg/taskproto/wrapper.go, writeContainerRun) runs its own docker invocations, for the identical reason ("AL2023's default user has passwordless sudo").
  • Rejected the docker-group-membership fix (option 2 in the issue): it would require a new login shell / newgrp to take effect, which doesn't fit nf-spawn's single-continuous-session execution model — sudo is simpler and matches an assumption already relied on elsewhere in this file.

Changes

Secondary observation (instance lifecycle lingering)

The issue also reported a failed task's instance not promptly terminating, and a completed task's instance lingering ~1-2 min post-completion. Investigated by reading spawn's pkg/agent/agent.go and pkg/taskproto/wrapper.go:

  • The completed-task ~1-2 min lingering is expected, bounded behavior: spored's lifecycle ticker (Agent.Monitor) that drives on_complete defaults to a 1-minute period, so a completion signal can wait up to ~1 tick before being acted on.
  • The failed-task instance allegedly staying running (not just laggy) is NOT clearly explained by reading the code: spawn task run's wrapper unconditionally writes the completion record and /tmp/SPAWN_COMPLETE regardless of the task's exit code, so a failed task should self-terminate on the same ~1-2 min bound as a successful one. This needs a live re-run to confirm or refute (and may not even reproduce now that this docker-socket bug — which was making every task fail — is fixed). Rather than guess, I filed a separate issue: Investigate: failed-task instance reported still running past on_complete terminate (#92 secondary observation) #93.

Test plan

  • ./gradlew test — 97/97 tests pass (was 96 before this PR; added 1)
  • Confirmed the new test fails against pre-fix code, passes after the fix
  • ./gradlew check — clean
  • Real-AWS verification (a live containerized task run on a stock AMI) — left as a follow-up for a human to run; not done here per the no-billable-infra constraint on this change

…ssion (#92)

Every containerized process failed exit 126 with "permission denied" on
/var/run/docker.sock. nf-spawn's ensureDocker step installs Docker but never
puts the task user in the docker group (and a mid-session usermod wouldn't
take effect anyway, since setup and the task run in one continuous shell).
Prefix the docker run invocation with sudo instead — the task user already
has passwordless sudo (relied on by ensureDocker's own dnf/systemctl calls),
and this matches spawn's own task wrapper, which runs its docker calls the
same way.

Fixes #92.
@scttfrdmn
scttfrdmn merged commit 829dd71 into main Sep 5, 2026
4 checks passed
@scttfrdmn
scttfrdmn deleted the fix/92-docker-socket-permission branch September 5, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Containerized processes fail exit 126: nf-spawn's docker run can't reach the Docker socket (task user not in docker group)

1 participant