{"record":{"id":"d75b1f1f0a6534bb","repo":"go-delve/delve","slug":"stub-exited-while-waiting-for-connection-v","errorCode":null,"errorMessage":"stub exited while waiting for connection: %v","messagePattern":"stub exited while waiting for connection: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/gdbserial/gdbserver.go","lineNumber":304,"sourceCode":"\n\tgo func() {\n\t\tconn, _ := listener.Accept()\n\t\tacceptChan <- conn\n\t}()\n\n\tselect {\n\tcase conn := <-acceptChan:\n\t\tlistener.Close()\n\t\tif conn == nil {\n\t\t\treturn nil, errors.New(\"could not connect\")\n\t\t}\n\t\treturn p.Connect(conn, path, cmdline, pid, debugInfoDirs, stopReason)\n\tcase status := <-p.waitChan:\n\t\tlistener.Close()\n\t\tif err := checkRosettaExpensive(); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn nil, fmt.Errorf(\"stub exited while waiting for connection: %v\", status)\n\t}\n}\n\n// Dial attempts to connect to the stub.\nfunc (p *gdbProcess) Dial(addr string, path, cmdline string, pid int, debugInfoDirs []string, stopReason proc.StopReason) (*proc.TargetGroup, error) {\n\tfor {\n\t\tconn, err := net.Dial(\"tcp\", addr)\n\t\tif err == nil {\n\t\t\treturn p.Connect(conn, path, cmdline, pid, debugInfoDirs, stopReason)\n\t\t}\n\t\tselect {\n\t\tcase status := <-p.waitChan:\n\t\t\tif err := checkRosettaExpensive(); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\treturn nil, fmt.Errorf(\"stub exited while attempting to connect: %v\", status)\n\t\tdefault:\n\t\t}","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/gdbserial/gdbserver.go#L286-L322","documentation":"When Delve launches a gdbserial-compatible stub (lldb, macOS debugserver, etc.) via Listen, it spawns the stub process and waits for its connection port before connecting. This error is returned when the stub process exits (reported via waitChan) before any connection could be established; the wrapped status contains the process exit status.","triggerScenarios":"Calling debugger.Listen() with a gdbserial backend where the spawned stub (debugserver/lldb-server) dies before accepting the debugger's connection — bad stub path, missing entitlements, crash at startup, or unsupported platform (e.g. Rosetta issue caught by checkRosettaExpensive).","commonSituations":"macOS: debugserver lacking code-signing entitlements or blocked by SIP; wrong --init or headless configuration pointing at a nonexistent stub binary; stub killed by security software; running under Rosetta with incompatible stub/architecture.","solutions":["Check the wrapped exit status in the message and run the stub manually to see its stderr (e.g. run the lldb-server/debugserver command directly).","On macOS, verify debugserver is properly signed and has the required entitlements (DevToolsSecurity, get-task-allow).","Verify the stub binary path/architecture matches the target (arm64 vs amd64, avoid Rosetta mismatches).","Upgrade Delve and the stub (Xcode command line tools for debugserver) to compatible versions."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"cmd := exec.Command(stubPath, args...)\nif err := cmd.Start(); err != nil {\n    return fmt.Errorf(\"stub %s failed to start: %w\", stubPath, err)\n}\n// ensure the stub process is alive before Listen\nif cmd.ProcessState != nil {\n    return fmt.Errorf(\"stub exited immediately; run it manually to see stderr\")\n}","typeGuard":"func stubAlive(p *os.Process) bool {\n    return p != nil && p.Signal(syscall.Signal(0)) == nil\n}","tryCatchPattern":"tg, err := dbg.Listen(...)\nif err != nil && strings.Contains(err.Error(), \"stub exited while waiting for connection\") {\n    return fmt.Errorf(\"debug stub failed at startup: %w (check entitlements/signing on macOS)\", err)\n}","preventionTips":["On macOS verify debugserver signing and DevToolsSecurity enabled","Confirm the stub binary exists and matches target architecture","Run the stub manually once to inspect its startup errors","Keep Xcode CLT / lldb-server versions compatible with your Delve"],"tags":["gdbserial","macos","lldb","process-exit","launch"],"backgroundTag":"stub-exited-before-connection","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}