hashicorp/nomad · error

error streaming previous alloc %q for new alloc %q; failed r

Error message

error streaming previous alloc %q for new alloc %q; failed reading error message: %w

What it means

During migration of a previous allocation's directory, streamAllocDir receives a tar stream. If the stream contains the special error snapshot file (errorFilename), the remote side failed; Nomad tries to read the original error message out of that file. This error is thrown when reading that embedded error file itself fails (other than a clean EOF), so the real remote error message is unavailable.

Source

Thrown at client/allocwatcher/alloc_watcher.go:607

		}

		if err != nil {
			return fmt.Errorf("error streaming previous alloc %q for new alloc %q: %w",
				p.prevAllocID, p.allocID, err)
		}

		if escapes, err := escapingfs.PathEscapesAllocDir(dest, "", hdr.Name); err != nil {
			return fmt.Errorf("error evaluating object: %w", err)
		} else if escapes {
			return fmt.Errorf("archive contains object that escapes alloc dir")
		}

		if hdr.Name == errorFilename {
			// Error snapshotting on the remote side, try to read
			// the message out of the file and return it.
			errBuf := make([]byte, int(hdr.Size))
			if _, err := tr.Read(errBuf); err != nil && err != io.EOF {
				return fmt.Errorf("error streaming previous alloc %q for new alloc %q; failed reading error message: %w",
					p.prevAllocID, p.allocID, err)
			}
			return fmt.Errorf("error streaming previous alloc %q for new alloc %q: %s",
				p.prevAllocID, p.allocID, string(errBuf))
		}

		// If the header is for a directory we create the directory
		if hdr.Typeflag == tar.TypeDir {
			name := filepath.Join(dest, hdr.Name)
			os.MkdirAll(name, os.FileMode(hdr.Mode))

			// Can't change owner if not root or on Windows.
			if euid == 0 {
				if err := os.Chown(name, hdr.Uid, hdr.Gid); err != nil {
					return fmt.Errorf("error chowning directory %w", err)
				}
			}
			continue

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Check connectivity between the new and previous allocation's clients and retry the migration
  2. Verify the previous allocation's client is healthy and can finish streaming its dir snapshot
  3. Inspect the tar stream for truncation/corruption; re-run node cleanup or GC and retry
  4. Fall back to the returned error's wrapped cause (the %w tar read error) for the root failure

Example fix

// before
errBuf := make([]byte, int(hdr.Size))
if _, err := tr.Read(errBuf); err != nil && err != io.EOF {
    return fmt.Errorf("error streaming previous alloc %q for new alloc %q; failed reading error message: %w", p.prevAllocID, p.allocID, err)
}
// after
errBuf := make([]byte, int(hdr.Size))
if _, err := io.ReadFull(tr, errBuf); err != nil && err != io.EOF && err != io.ErrUnexpectedEOF {
    return fmt.Errorf("error streaming previous alloc %q for new alloc %q; failed reading error message: %w", p.prevAllocID, p.allocID, err)
}
Defensive patterns

Strategy: retry

Validate before calling

// Before triggering migration, ensure the previous alloc's client is reachable
// and the node is healthy:
// if client.Healthy() && prevAllocNode.Ready() { proceed with migration }

Try / catch

if err := watcher.Wait(ctx); err != nil {
    if strings.Contains(err.Error(), "failed reading error message") {
        // stream was interrupted; retry migration or start alloc without migration
        return retryMigration(ctx, alloc)
    }
    return err
}

Prevention

When it happens

Trigger: The tar stream from the remote client contains a header named errorFilename, and tr.Read into errBuf returns an error that is not io.EOF (e.g. tar stream truncated, connection reset mid-read, corrupted archive).

Common situations: Network interruption while migrating an allocation between nodes; the previous allocation's client crashed mid-stream; TAR reader state corruption after a prior malformed entry.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/cb5bebcbde2872b7. Report an issue: GitHub.