Skip to content

--attach-volume mounts run AFTER the --user-data/--command script, so a program in user-data can't see the volumes #166

Closed

Description

@scttfrdmn

Summary

spawn launch --attach-volume snap:/mount:ro --user-data-file <script> mounts the attached volume after the user-data script has already run (to completion). So anything the user-data script launches that needs the volume sees an unmounted mount point. The mount lands too late to be useful to the launched workload.

Evidence

A head node launched with two --attach-volume snapshots and a user-data script that runs an nf-core pipeline (which validates that the DB mount paths exist). The instance's own boot log, in order:

+ tmux send-keys ... run_pipeline.sh ...        # user-data launches the pipeline
...                                             # pipeline runs ~9 min, then fails:
  ERROR  db_path '/opt/databases/metaphlan' does not exist
  Summary written: 0 samples
+ touch /tmp/SPAWN_COMPLETE
+ echo '=== Head node complete ... ==='         # 08:49:09 — user-data DONE
+ mkdir -p /opt/databases/kraken2               # <-- volume mount starts AFTER
+ mount -o ro,noatime /dev/nvme1n1 /opt/databases/kraken2
+ mkdir -p /opt/databases/metaphlan
+ mount -o ro,noatime /dev/nvme2n1 /opt/databases/metaphlan

The --attach-volume mounts (mkdir + mount -o ro) only run after the user-data script printed its completion line. By then the pipeline had already validated the (still-unmounted) paths and aborted. df/ls after boot confirm both volumes are correctly mounted RO with the right contents — just too late.

(One path "passed" validation only because the AMI happened to have an empty dir at that mount point — an existence check on an empty dir — which made the bug look like it affected only one of the two volumes.)

Expected

--attach-volume volumes should be attached and mounted before the --user-data / --command script runs (the script is the workload; it's the thing most likely to need the volume). Mounting after the workload finishes is effectively never useful.

If strict ordering is hard, at minimum a documented barrier the user-data can wait on (e.g. spawn writes a /run/spawn/volumes-ready marker once all --attach-volume mounts are live, so a script can until [ -f /run/spawn/volumes-ready ]; do sleep 1; done before using them).

Workaround I'll use meanwhile

Have the user-data script itself wait for the expected mounts (mountpoint -q /opt/databases/kraken2) before starting the pipeline — but that only works if I know the mount paths in the script, and it's racing spawn's own mount logic. A guaranteed pre-user-data mount (or a ready-marker) is the real fix.

Context

spawn 0.50.0, nf-spawn 0.5.0 (whose ext.volumes head-side recipe relies on the head having the DB mounted before nextflow run validates db_path). AL2023 arm64, head launched via nf-spawn's launcher with --user-data-file. Tasks (also --attach-volume) likely have the same ordering relative to the task script — worth checking, since the whole ext.volumes zero-copy path depends on the volume being mounted before the task's .command.sh runs.

Activity

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

    @scttfrdmn
    ContributorAuthor

    Confirmed and fixed in v0.51.1 (#167). Your boot-log diagnosis was exactly right — the mount script was appended to the end of user-data, so it ran after the workload finished.

    Fix: the storage mount (EFS / FSx / --attach-volume) is now injected before the user's --user-data/--command script in the bootstrap, not after it. So by the time your pipeline runs, the volumes are already mounted. Also removed the job-array path's separate storage re-append (it would have double-mounted and re-introduced the late ordering now that the base carries the mount).

    This covers the task side too (which you correctly flagged to check): nf-spawn ships its task staging script as --user-data-file, i.e. it's the CustomUserData — so the task's .command.sh now also runs after the mount. The ext.volumes zero-copy path (symlink stage-name → mount) depends on exactly that ordering, so this was a real blocker for it.

    You can drop the mountpoint -q workaround — the mount is guaranteed live before your script starts now.

    One thing: the ordering is baked into user-data at launch time, so this needs a fresh launch on spawn ≥ 0.51.1 (re-tag/upgrade, then relaunch the head + tasks). Existing instances keep the old user-data. brew upgrade spawn / scoop update spawn once v0.51.1's release finishes (building now).

    This is almost certainly why the smoke test would've failed regardless of the nf-spawn 0.5.0 symlink work — the head validated db_path before spawn mounted the volume. With this in, the head mount is live before nextflow run.

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