{"record":{"id":"154c5ceba6d4644c","repo":"hashicorp/nomad","slug":"failed-to-write-bootstrap-environment-w","errorCode":null,"errorMessage":"failed to write bootstrap environment: %w","messagePattern":"failed to write bootstrap environment: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/allocrunner/taskrunner/envoy_bootstrap_hook.go","lineNumber":333,"sourceCode":"\tbootstrapArgs := bootstrap.args()\n\n\t// Write args to file for debugging\n\targsFile, err := os.Create(bootstrapCmdPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to write bootstrap command line: %w\", err)\n\t}\n\tdefer argsFile.Close()\n\tif _, err := io.WriteString(argsFile, strings.Join(bootstrapArgs, \" \")+\"\\n\"); err != nil {\n\t\treturn fmt.Errorf(\"failed to encode bootstrap command line: %w\", err)\n\t}\n\n\t// Create environment\n\tbootstrapEnv := bootstrap.env(h.groupEnv())\n\n\t// Write env to file for debugging\n\tenvFile, err := os.Create(bootstrapEnvPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to write bootstrap environment: %w\", err)\n\t}\n\tdefer envFile.Close()\n\tenvEnc := json.NewEncoder(envFile)\n\tenvEnc.SetIndent(\"\", \"    \")\n\tif err := envEnc.Encode(bootstrapEnv); err != nil {\n\t\treturn fmt.Errorf(\"failed to encode bootstrap environment: %w\", err)\n\t}\n\n\t// keep track of latest error returned from exec-ing consul envoy bootstrap\n\tvar cmdErr error\n\n\tbackoffOpts := decay.BackoffOptions{\n\t\tMaxSleepTime:   h.envoyBootstrapWaitTime,\n\t\tInitialGapSize: h.envoyBootstrapInitialGap,\n\t\tMaxJitterSize:  h.envoyBootstrapMaxJitter,\n\t\tSleeper:        h.envoyBootstrapExpSleep,\n\t}\n","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/allocrunner/taskrunner/envoy_bootstrap_hook.go#L315-L351","documentation":"The hook also writes the envoy bootstrap environment variables as JSON to .envoy_bootstrap.env in the SecretsDir for debugging. os.Create failing for this env file produces 'failed to write bootstrap environment', wrapping the OS error. As with the .cmd file, this affects only the debug artifact path in Prestart.","triggerScenarios":"os.Create(bootstrapEnvPath) fails due to a missing/read-only SecretsDir, ENOSPC, or permission/SELinux restrictions on file creation in the secrets directory.","commonSituations":"Client disk full; secrets dir permissions broken after host changes; containerized client where the secrets mount is not writable.","solutions":["Check the wrapped OS error to identify the filesystem cause","Verify SecretsDir exists and the Nomad client user can create files in it","Free disk space if ENOSPC","Correct security-module (SELinux/AppArmor) denials if present","Retry the allocation once the filesystem is healthy"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if info, err := os.Stat(secretsDir); err != nil || !info.IsDir() {\n    return fmt.Errorf(\"env bootstrap target dir %s unavailable: %w\", secretsDir, err)\n}\nif free, err := diskFree(secretsDir); err == nil && free < 1<<20 {\n    return errors.New(\"insufficient disk space for envoy bootstrap debug files\")\n}","typeGuard":null,"tryCatchPattern":"if err := hook.Prestart(req); err != nil {\n    var pe *os.PathError\n    if errors.As(err, &pe) && strings.Contains(err.Error(), \"bootstrap environment\") {\n        log.Printf(\"env debug file creation failed on %s: %v\", pe.Path, pe.Err)\n    }\n    return err\n}","preventionTips":["Verify secrets dir existence/permissions before the envoy hook runs","Alert on low disk space for the client data volume","Ensure mounts used by the client (including in containers) are writable","Fix SELinux/AppArmor denials affecting the secrets directory"],"tags":["envoy","consul-connect","filesystem"],"backgroundTag":"file-write-permission-denied","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"}