{"record":{"id":"9fb01fe54b3d2bdf","repo":"go-delve/delve","slug":"process-d-has-exited-with-status-d-9fb01f","errorCode":null,"errorMessage":"Process %d has exited with status %d","messagePattern":"Process (.+?) has exited with status (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"service/rpc2/client.go","lineNumber":130,"sourceCode":"\nfunc (c *RPCClient) DirectionCongruentContinue() <-chan *api.DebuggerState {\n\treturn c.continueDir(api.DirectionCongruentContinue)\n}\n\nfunc (c *RPCClient) continueDir(cmd string) <-chan *api.DebuggerState {\n\tch := make(chan *api.DebuggerState)\n\tgo func() {\n\t\tfor {\n\t\t\tout := new(CommandOut)\n\t\t\terr := c.callWhileDrainingEvents(\"Command\", &api.DebuggerCommand{Name: cmd, ReturnInfoLoadConfig: c.retValLoadCfg, WithEvents: c.eventsFn != nil}, &out)\n\t\t\tstate := out.State\n\t\t\tif err != nil {\n\t\t\t\tstate.Err = err\n\t\t\t}\n\t\t\tif state.Exited {\n\t\t\t\t// Error types apparently cannot be marshalled by Go correctly. Must reset error here.\n\t\t\t\t//lint:ignore ST1005 backwards compatibility\n\t\t\t\tstate.Err = fmt.Errorf(\"Process %d has exited with status %d\", c.ProcessPid(), state.ExitStatus)\n\t\t\t}\n\t\t\tch <- &state\n\t\t\tif err != nil || state.Exited {\n\t\t\t\tclose(ch)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tisbreakpoint := false\n\t\t\tistracepoint := true\n\t\t\tfor i := range state.Threads {\n\t\t\t\tif state.Threads[i].Breakpoint != nil {\n\t\t\t\t\tisbreakpoint = true\n\t\t\t\t\tistracepoint = istracepoint && (state.Threads[i].Breakpoint.Tracepoint || state.Threads[i].Breakpoint.TraceReturn)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif !isbreakpoint || !istracepoint {\n\t\t\t\tclose(ch)","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/service/rpc2/client.go#L112-L148","documentation":"Client-side state notification in service/rpc2/client.go: when the debuggee terminates, the halted-state callback replaces any pending error with a message reporting the process pid and its exit status, because api.Err cannot be marshalled correctly over JSON-RPC. It signals the debug session has ended, not a debugger malfunction.","triggerScenarios":"Any continue/step/next RPC that observes state.Exited == true after the target process terminated; also delivered on the client's internal state listener channel.","commonSituations":"Program ran to completion (main returned); target crashed with a non-zero status; process called os.Exit; breakpoint-free run finished.","solutions":["Inspect state.ExitStatus / ExitStatus in the halted state to see the program's exit code","Set breakpoints or use stepping to stop before the program finishes","Handle the Exited flag in your client loop and stop issuing further RPCs","Re-launch the process (Restart) if more debugging is needed"],"exampleFix":"// before\nstate, err := client.GetStateNonBlocking()\nfmt.Println(state.Err)\n// after\nstate, err := client.GetStateNonBlocking()\nif state != nil && state.Exited {\n    fmt.Printf(\"process exited with %d\\n\", state.ExitStatus)\n} else {\n    fmt.Println(state.Err)\n}","handlingStrategy":"type-guard","validationCode":"// no pre-call validation possible; handle after RPC\nstate, err := client.GetStateNonBlocking()\nwillExit := err == nil && state != nil && state.Exited","typeGuard":"func isProcessExit(state *api.DebuggerState) bool { return state != nil && state.Exited }","tryCatchPattern":"state, err := client.GetStateNonBlocking()\nif err != nil {\n    if state != nil && state.Exited {\n        log.Printf(\"target exited: %d\", state.ExitStatus)\n        return nil // expected termination, not an RPC failure\n    }\n    return err\n}","preventionTips":["Always check state.Exited before treating state.Err as a real failure","Stop issuing stepping/continue RPCs once Exited is observed","Track ExitStatus for exit-code reporting","Use Restart to begin a new session after exit"],"tags":["rpc2","process-exit","lifecycle"],"backgroundTag":"debuggee-process-exited","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}