hashicorp/nomad · error

Unable to convert Gid to an int

Error message

Unable to convert Gid to an int: %w

What it means

getGid is the group-id counterpart of getUid: it parses u.Gid with strconv.Atoi and wraps any parse failure. It runs while dropDirPermissions converts the resolved 'nobody' user's primary group for the subsequent os.Chown.

Solutions

  1. Fix the gid field for the user via `getent passwd nobody` inspection and edit /etc/passwd (or the NSS source).
  2. Ensure the referenced group exists with a numeric gid in /etc/group.
  3. Restore standard system user/group files on minimal images.
  4. Restart the Nomad client after the repair.

Example fix

// before: non-numeric gid
nobody:x:65534:nogroup-nonnumeric::/nonexistent:/sbin/nologin
// after
nobody:x:65534:65534:nobody:/nonexistent:/sbin/nologin
Defensive patterns

Strategy: validation

Validate before calling

// preflight: referenced users must have numeric gids
u, err := user.Lookup(taskUser)
if err != nil { return err }
if _, err := strconv.Atoi(u.Gid); err != nil {
    return fmt.Errorf("user %s has non-numeric gid %q", taskUser, u.Gid)
}

Try / catch

if err := td.Build(); err != nil {
    if strings.Contains(err.Error(), "convert Gid to an int") {
        log.Printf("corrupt gid for task user; repair /etc/passwd or /etc/group")
    }
    return err
}

Prevention

When it happens

Trigger: strconv.Atoi(u.Gid) failed because the Gid string on the looked-up user is not a valid integer.

Common situations: Corrupted /etc/passwd or NSS source where the gid field is non-numeric; hand-edited entries; broken container images.

Related errors


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

Appendix: source

Thrown at client/allocdir/fs_unix.go:82

	return nil
}

// getUid for a user
func getUid(u *user.User) (int, error) {
	uid, err := strconv.Atoi(u.Uid)
	if err != nil {
		return 0, fmt.Errorf("Unable to convert Uid to an int: %w", err)
	}

	return uid, nil
}

// getGid for a user
func getGid(u *user.User) (int, error) {
	gid, err := strconv.Atoi(u.Gid)
	if err != nil {
		return 0, fmt.Errorf("Unable to convert Gid to an int: %w", err)
	}

	return gid, nil
}

// linkOrCopy attempts to hardlink dst to src and fallsback to copying if the
// hardlink fails.
func linkOrCopy(src, dst string, uid, gid int, perm os.FileMode) error {
	// Avoid link/copy if the file already exists in the chroot
	// TODO 0.6 clean this up. This was needed because chroot creation fails
	// when a process restarts.
	if fileInfo, _ := os.Stat(dst); fileInfo != nil {
		return nil
	}
	// Attempt to hardlink.
	if err := os.Link(src, dst); err == nil {
		return nil
	}

View on GitHub (pinned to 482b49bf1a)