{"record":{"id":"3a3a24e9f8425c7a","repo":"hashicorp/nomad","slug":"panic-err-3a3a24","errorCode":null,"errorMessage":"panic(err)","messagePattern":"panic\\(err\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/logmon/plugin.go","lineNumber":23,"sourceCode":"\nimport (\n\t\"context\"\n\t\"os\"\n\t\"os/exec\"\n\n\t\"github.com/hashicorp/go-hclog\"\n\t\"github.com/hashicorp/go-plugin\"\n\t\"github.com/hashicorp/nomad/client/logmon/proto\"\n\t\"github.com/hashicorp/nomad/plugins/base\"\n\t\"google.golang.org/grpc\"\n)\n\nvar bin = getBin()\n\nfunc getBin() string {\n\tb, err := os.Executable()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn b\n}\n\n// LaunchLogMon launches a new logmon or reattaches to an existing one.\n// TODO: Integrate with base plugin loader\nfunc LaunchLogMon(logger hclog.Logger, reattachConfig *plugin.ReattachConfig) (LogMon, *plugin.Client, error) {\n\tlogger = logger.Named(\"logmon\")\n\tconf := &plugin.ClientConfig{\n\t\tHandshakeConfig: base.Handshake,\n\t\tPlugins: map[string]plugin.Plugin{\n\t\t\t\"logmon\": &Plugin{},\n\t\t},\n\t\tAllowedProtocols: []plugin.Protocol{\n\t\t\tplugin.ProtocolGRPC,\n\t\t},\n\t\tLogger: logger,\n\t}","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/logmon/plugin.go#L5-L41","documentation":"logmon resolves its own plugin binary path at package init time via os.Executable(); the package-level `var bin = getBin()` runs during process startup. If the OS cannot determine the executable path, the error is unrecoverable for the plugin and is panicked.","triggerScenarios":"Package initialization of client/logmon when os.Executable() fails — e.g. the executable file was deleted/replaced after start, /proc is unavailable, or the process was launched in a way the OS cannot trace back to a binary path.","commonSituations":"Binary deleted or upgraded (moved) while the agent process is running; running in minimal containers with odd /proc mounts; exec'ing the Nomad binary from a temp file that was removed; unusual embedding environments where os.Executable returns an error.","solutions":["Ensure the Nomad executable file still exists on disk while the process runs; don't delete/replace the binary in place during upgrades","Upgrade via unlink+replace of a new file rather than truncating/moving the running binary path","Check the underlying err in the panic to identify the OS-level cause (permission, missing /proc, deleted file)","Restart the agent from a valid, existing binary path"],"exampleFix":"// before\nvar bin = getBin() // panics at init on error\n// after\nvar bin = func() string {\n    b, err := os.Executable()\n    if err != nil {\n        b = os.Args[0] // fallback instead of panicking\n    }\n    return b\n}()","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"// package init cannot be recovered from inside the package; wrap usage\nfunc initLogmon() (err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"logmon init failed: %v\", r)\n        }\n    }()\n    _ = logmon.Plugin // triggers bin resolution\n    return nil\n}\n","preventionTips":["Never delete or move the running Nomad binary in place; replace atomically","Verify os.Executable() works in your container/runtime environment before upgrade","Keep /proc mounted properly in containers"],"tags":["executable-path","startup","panic","os"],"backgroundTag":"os-executable-path-failure","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"}