{"record":{"id":"d71b033be2566cf4","repo":"hashicorp/nomad","slug":"unable-to-convert-gid-to-an-int-w","errorCode":null,"errorMessage":"Unable to convert Gid to an int: %w","messagePattern":"Unable to convert Gid to an int: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/allocdir/fs_unix.go","lineNumber":82,"sourceCode":"\n\treturn nil\n}\n\n// getUid for a user\nfunc getUid(u *user.User) (int, error) {\n\tuid, err := strconv.Atoi(u.Uid)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"Unable to convert Uid to an int: %w\", err)\n\t}\n\n\treturn uid, nil\n}\n\n// getGid for a user\nfunc getGid(u *user.User) (int, error) {\n\tgid, err := strconv.Atoi(u.Gid)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"Unable to convert Gid to an int: %w\", err)\n\t}\n\n\treturn gid, nil\n}\n\n// linkOrCopy attempts to hardlink dst to src and fallsback to copying if the\n// hardlink fails.\nfunc linkOrCopy(src, dst string, uid, gid int, perm os.FileMode) error {\n\t// Avoid link/copy if the file already exists in the chroot\n\t// TODO 0.6 clean this up. This was needed because chroot creation fails\n\t// when a process restarts.\n\tif fileInfo, _ := os.Stat(dst); fileInfo != nil {\n\t\treturn nil\n\t}\n\t// Attempt to hardlink.\n\tif err := os.Link(src, dst); err == nil {\n\t\treturn nil\n\t}","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/allocdir/fs_unix.go#L64-L100","documentation":"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.","triggerScenarios":"strconv.Atoi(u.Gid) failed because the Gid string on the looked-up user is not a valid integer.","commonSituations":"Corrupted /etc/passwd or NSS source where the gid field is non-numeric; hand-edited entries; broken container images.","solutions":["Fix the gid field for the user via `getent passwd nobody` inspection and edit /etc/passwd (or the NSS source).","Ensure the referenced group exists with a numeric gid in /etc/group.","Restore standard system user/group files on minimal images.","Restart the Nomad client after the repair."],"exampleFix":"// before: non-numeric gid\nnobody:x:65534:nogroup-nonnumeric::/nonexistent:/sbin/nologin\n// after\nnobody:x:65534:65534:nobody:/nonexistent:/sbin/nologin","handlingStrategy":"validation","validationCode":"// preflight: referenced users must have numeric gids\nu, err := user.Lookup(taskUser)\nif err != nil { return err }\nif _, err := strconv.Atoi(u.Gid); err != nil {\n    return fmt.Errorf(\"user %s has non-numeric gid %q\", taskUser, u.Gid)\n}","typeGuard":null,"tryCatchPattern":"if err := td.Build(); err != nil {\n    if strings.Contains(err.Error(), \"convert Gid to an int\") {\n        log.Printf(\"corrupt gid for task user; repair /etc/passwd or /etc/group\")\n    }\n    return err\n}","preventionTips":["Run `pwck`/`grpck` during host provisioning to catch malformed entries.","Prefer useradd/groupadd over manual edits.","Validate users referenced in jobspecs resolve to numeric ids on every client."],"tags":["users","parsing","linux","nomad"],"backgroundTag":"invalid-user-id","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}