{"record":{"id":"739ad75c76ab45f1","repo":"go-delve/delve","slug":"error-while-waiting-for-task","errorCode":null,"errorMessage":"error while waiting for task","messagePattern":"error while waiting for task","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/native/proc_darwin.go","lineNumber":345,"sourceCode":"\t\t\t_, status, err := dbp.wait(dbp.pid, 0)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tdbp.postExit()\n\t\t\treturn nil, proc.ErrProcessExited{Pid: dbp.pid, Status: status.ExitStatus()}\n\n\t\tcase C.MACH_RCV_INTERRUPTED:\n\t\t\thalt := dbp.os.halt\n\t\t\tif !halt {\n\t\t\t\t// Call trapWait again, it seems\n\t\t\t\t// MACH_RCV_INTERRUPTED is emitted before\n\t\t\t\t// process natural death _sometimes_.\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\treturn nil, nil\n\n\t\tcase 0:\n\t\t\treturn nil, fmt.Errorf(\"error while waiting for task\")\n\t\t}\n\n\t\t// In macOS 10.12.1 if we received a notification for a task other than\n\t\t// the inferior's task and the inferior's task is no longer valid, this\n\t\t// means inferior called execve and its task_t changed.\n\t\tif dbp.os.task != task && C.task_is_valid(dbp.os.task) == 0 {\n\t\t\tdbp.os.task = task\n\t\t\tkret := C.reset_exception_ports(dbp.os.task, &dbp.os.exceptionPort, &dbp.os.notificationPort)\n\t\t\tif kret != C.KERN_SUCCESS {\n\t\t\t\treturn nil, fmt.Errorf(\"could not follow task across exec: %d\\n\", kret)\n\t\t\t}\n\t\t}\n\n\t\t// Since we cannot be notified of new threads on OS X\n\t\t// this is as good a time as any to check for them.\n\t\tdbp.updateThreadList()\n\t\tth, ok := dbp.threads[int(port)]\n\t\tif !ok {","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/native/proc_darwin.go#L327-L363","documentation":"trapWait blocks until the debuggee reports a mach message (stop, exit, etc.). If the underlying wait loop receives status 0 — no valid notification — Delve returns \"error while waiting for task\", meaning the wait for the inferior's event produced nothing usable and the debugger state is indeterminate.","triggerScenarios":"While continue/stepping on macOS, the mach_msg-based wait in trapWait hits its `case 0:` branch: the notification port returned no event, e.g. the task died without delivering an exit notification or the message was consumed unexpectedly.","commonSituations":"Inferior crashes hard (killed by SIGKILL) so no mach exit notification arrives; debugging over an SSH session where the task is torn down; concurrent debuggers stealing exception messages.","solutions":["Check whether the inferior was killed externally (dmesg, `ps`) — e.g. SIGKILL from the OS or OOM killer.","Rerun the session; this condition is usually terminal for the debug session.","Avoid running other debug instruments (lldb, Instruments) on the same process simultaneously.","Update Delve — mach wait handling has changed across macOS versions (notably 10.12+)."],"exampleFix":"// before\nsudo kill -9 <pid>   // externally kills inferior mid-session\n// after\ndeliver signals from within the debugger: (dlv) continue  // then use halt/kill commands","handlingStrategy":"retry","validationCode":"// Before continuing, record that the target is alive:\n// if the inferior can be SIGKILLed externally, monitor it:\ncmd := exec.Command(\"ps\", \"-p\", strconv.Itoa(pid))\nif err := cmd.Run(); err != nil {\n    return fmt.Errorf(\"inferior %d gone before wait\", pid)\n}","typeGuard":null,"tryCatchPattern":"_, err := dbp.trapWait(pid)\nif err != nil && strings.Contains(err.Error(), \"error while waiting for task\") {\n    // verify the process wasn't SIGKILLed; restart the session rather than retrying\n}","preventionTips":["Never SIGKILL the inferior from outside a live debug session.","Don't run competing debug tooling that consumes mach exception messages.","Keep Delve updated for your macOS release.","Treat this error as terminal: check the process and relaunch."],"tags":["darwin","mach","wait","process-death"],"backgroundTag":"mach-wait-no-event","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}