Skip to content

Tasks stuck in PENDING — Nextflow abandons tasks before spawn instance boots #12

Closed

Description

@scttfrdmn

Summary

Nextflow tasks dispatched via nf-spawn get stuck in PENDING state and Nextflow exits without running them. The spawn instance launches successfully (visible in spawn list) but Nextflow's task polling monitor times out before --wait-for-ssh completes.

Log evidence

[Task submitter] INFO  io.nextflow.spawn.SpawnTaskHandler - Submitting task 'FETCH_FASTQ (1)' to spawn instance 'nf-xxx' (t4g.medium in us-east-1)
[Task monitor] DEBUG n.processor.TaskPollingMonitor - !! executor spawn > No more task to compute -- The following nodes are still active:
  [operator] map
  [operator] collectFile
  [operator] subscribe

WorkflowStats[succeededCount=0; failedCount=0; pendingCount=2; submittedCount=0; runningCount=0]

The instance appears in spawn list as running but Nextflow never marks it as running or complete.

Root cause

SpawnTaskHandler.submit() calls spawn launch --wait-for-ssh which blocks until the instance is SSH-ready (~1-2 min). Nextflow's task polling monitor has a shorter effective timeout and gives up before --wait-for-ssh returns.

Possible fixes

  1. Run spawn launch with --wait-for-running (faster) instead of --wait-for-ssh
  2. Make the SSH wait timeout configurable via ext.sshTimeout or similar
  3. Run spawn launch asynchronously and poll the instance state separately

Context

Activity

  1. added
    bug
    on Jun 3, 2026
  2. scttfrdmn commented on Jun 3, 2026

    @scttfrdmn
    CollaboratorAuthor

    Traced this through both nf-spawn and spawn. The stated root cause doesn't match the code — and there are two real bugs underneath the symptom.

    The reported cause is already addressed

    The issue says SpawnTaskHandler.submit() calls spawn launch --wait-for-ssh and blocks ~1-2 min. But both current main and the v0.2.0 tag this was filed against already launch with:

    '--wait-for-running=false',
    '--wait-for-ssh=false',

    (SpawnTaskHandler.groovy:57-58)

    So submit() does not block on SSH — "possible fix #1" is already in place. The PENDING hang has a different cause.

    Real bug A — --user-data is passed as a bare path, so the task script never runs

    The handler writes the task script to a temp file and passes it as:

    '--user-data', scriptFile.toString(),   // SpawnTaskHandler.groovy:56

    But spawn's --user-data flag means "@file or inline". A value without a leading @ is treated as inline user-data:

    // spawn cmd/launch.go:1938-1952
    } else if userData != "" {
        if strings.HasPrefix(userData, "@") {
            path := userData[1:]
            data, _ := os.ReadFile(path)
            customUserData = string(data)
        } else {
            customUserData = userData   // <-- bare path baked in literally
        }
    }

    So spawn bakes the literal string /tmp/nf-spawn-nf-xxx-….sh into the instance's user-data instead of the script contents. The task body is never executed on the instance.

    Fix: prefix with @ ('--user-data', '@' + scriptFile.toString()) or use the dedicated --user-data-file flag, which reads the file unconditionally (launch.go:1928).

    Real bug B — no output staging back to task.workDir (the actual PENDING cause)

    There is no copy-back logic anywhere in nf-spawn — no scp, no S3 download, no .exitcode / .command.out / .command.err handling (grep is empty). buildTaskScript() runs the script in a remote working dir and only writes a SPAWN_COMPLETE marker.

    But Nextflow finalizes a task by reading .exitcode plus the declared output files in task.workDir (the local/shared work directory). Those files never materialize there, so the task can't bind its outputs. Its consumers therefore never become runnable and sit in PENDING — which is exactly the log:

    No more task to compute -- The following nodes are still active: [operator] map / collectFile / subscribe
    pendingCount=2; submittedCount=0
    

    FETCH_FASTQ (1) was submitted (per the log); the two stuck tasks are its downstream consumers, blocked because FETCH_FASTQ produced no retrievable outputs.

    Fix (design decision needed): stage results back to task.workDir. Options:

    • Have buildTaskScript() write .exitcode and the declared outputs to a shared filesystem mounted at task.workDir (the cleanest path if work dir is an S3/EFS mount both sides see).
    • Or scp the work dir back from the instance before it self-terminates — but note --on-complete terminate means we must copy back before termination, and spawn status can't reach a terminated instance to do it afterward.

    Suggested issue updates

    • Correct the root-cause section (the --wait-for-ssh analysis is stale).
    • Split into two: (A) --user-data @-prefix one-liner fix; (B) output staging, which is the substantive design item and the real reason tasks hang in PENDING.

    Bug A is a trivial fix; bug B is the blocker. Happy to take both once the staging approach (shared FS vs scp-before-terminate) is decided.

  3. scttfrdmn commented on Jun 3, 2026

    @scttfrdmn
    CollaboratorAuthor

    Closing in favor of two focused issues. The root cause described here (submit() blocking on spawn launch --wait-for-ssh) is stale — both main and the v0.2.0 tag already launch with --wait-for-running=false --wait-for-ssh=false, so that's not it.

    The real causes, split out:

    #13 must land first (script has to actually run) before #14's staging can be validated end-to-end. Tracking the fix in those two.

  4. added a commit that references this issue on Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions