go-delve/delve · error
invalid process ID: %d
Error message
invalid process ID: %d
What it means
When creating a debugger in attach mode, a negative AttachPid is invalid (0 means 'not attaching'). New() validates this before attempting any process operation and rejects the configuration.
Source
Thrown at service/debugger/debugger.go:177
DisableASLR bool
RrOnProcessPid int
RrDelOnDetach bool
}
// New creates a new Debugger. ProcessArgs specify the commandline arguments for the
// new process.
func New(config *Config, processArgs []string) (*Debugger, error) {
logger := logflags.DebuggerLogger()
d := &Debugger{
config: config,
processArgs: processArgs,
log: logger,
}
// Validate AttachPid if specified
if d.config.AttachPid != 0 && d.config.AttachPid < 0 {
return nil, fmt.Errorf("invalid process ID: %d", d.config.AttachPid)
}
// Create the process by either attaching or launching.
switch {
case d.config.AttachPid > 0 || d.config.AttachWaitFor != "":
d.log.Infof("attaching to pid %d", d.config.AttachPid)
path := ""
if len(d.processArgs) > 0 {
path = d.processArgs[0]
}
var waitFor *proc.WaitFor
if d.config.AttachWaitFor != "" {
waitFor = &proc.WaitFor{
Name: d.config.AttachWaitFor,
Interval: time.Duration(d.config.AttachWaitForInterval * float64(time.Millisecond)),
Duration: time.Duration(d.config.AttachWaitForDuration * float64(time.Millisecond)),
}
}View on GitHub (pinned to a23773e6c3)
Solutions
- Pass a real positive PID from `ps` or `pgrep`
- Check the script/variable feeding the PID for empty/invalid values
- Leave AttachPid at 0 (unset) when launching instead of attaching
- Guard the value before calling New/debugger creation
Example fix
// before
cfg.AttachPid = pid // pid may be -1
// after
if pid <= 0 { return fmt.Errorf("need a positive pid, got %d", pid) }
cfg.AttachPid = pid Defensive patterns
Strategy: validation
Validate before calling
func validateAttachPid(pid int) error { if pid < 0 { return fmt.Errorf("invalid process ID: %d", pid) }; return nil } Type guard
func isAttachablePid(pid int) bool { return pid > 0 } Try / catch
if _, err := debugger.New(config, logger); err != nil { if strings.Contains(err.Error(), "invalid process ID") { /* resolve a real pid and retry */ } return err } Prevention
- Resolve PIDs via pgrep/ps before attaching
- Guard shell variables that may be empty/negative
- Leave AttachPid unset (0) for launch mode
When it happens
Trigger: dlv attach with a negative PID, or programmatic construction of service.Config with AttachPid set to a negative value.
Common situations: Scripts passing shell variables that are empty or negative into attach commands; arithmetic producing negative PIDs; UI clients sending -1 as a placeholder.
Related errors
- waitfor duration expired
- could not get thread count
- procstat_getprocs returned no processes
- negative maximum stack depth
- waitfor not implemented
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/8ae3624457eb474f.
Report an issue: GitHub.