{"record":{"id":"7ea76f16cb1c098c","repo":"go-delve/delve","slug":"could-not-resume-task","errorCode":null,"errorMessage":"could not resume task","messagePattern":"could not resume task","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/native/proc_darwin.go","lineNumber":195,"sourceCode":"\tif err != nil {\n\t\tdetachWithoutGroup(dbp, false)\n\t\treturn nil, err\n\t}\n\treturn tgt, nil\n}\n\n// Kill kills the process.\nfunc (procgrp *processGroup) kill(dbp *nativeProcess) (err error) {\n\tif ok, _ := dbp.Valid(); !ok {\n\t\treturn nil\n\t}\n\terr = sys.Kill(-dbp.pid, sys.SIGKILL)\n\tif err != nil {\n\t\treturn errors.New(\"could not deliver signal: \" + err.Error())\n\t}\n\tfor port := range dbp.threads {\n\t\tif C.thread_resume(C.thread_act_t(port)) != C.KERN_SUCCESS {\n\t\t\treturn errors.New(\"could not resume task\")\n\t\t}\n\t}\n\tfor {\n\t\tvar task C.task_t\n\t\tport := C.mach_port_wait(dbp.os.portSet, &task, C.int(0))\n\t\tif port == dbp.os.notificationPort {\n\t\t\tbreak\n\t\t}\n\t}\n\tdbp.postExit()\n\treturn\n}\n\nfunc (dbp *nativeProcess) requestManualStop() (err error) {\n\tvar (\n\t\ttask          = C.mach_port_t(dbp.os.task)\n\t\tthread        = C.mach_port_t(dbp.memthread.os.threadAct)\n\t\texceptionPort = C.mach_port_t(dbp.os.exceptionPort)","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/native/proc_darwin.go#L177-L213","documentation":"After killing the task on macOS, kill() resumes all known thread ports with C.thread_resume. If any Mach thread_resume call does not return KERN_SUCCESS, 'could not resume task' is returned — a Mach port/thread state failure during teardown.","triggerScenarios":"kill() iterating dbp.threads when a thread port is stale (thread already terminated), invalid, or the task is already dead, so thread_resume returns an error other than KERN_SUCCESS.","commonSituations":"Debuggee died between SIGKILL and the resume loop (stale thread ports in the map); thread terminated mid-session and its port became invalid; Mach port right revoked after task death.","solutions":["Verify the task is still valid before resuming threads; skip/ignore resume errors after SIGKILL since the task is being killed anyway","Clear stale thread entries from dbp.threads when threads terminate during the session","Ensure SIGKILL actually succeeded before resuming (check the preceding error)","Report upstream if reproducible — teardown should tolerate KERN_TERMINATED/KERN_INVALID_RIGHT from thread_resume"],"exampleFix":"// before\nfor port := range dbp.threads {\n    if C.thread_resume(C.thread_act_t(port)) != C.KERN_SUCCESS {\n        return errors.New(\"could not resume task\")\n    }\n}\n// after\nfor port := range dbp.threads {\n    if kr := C.thread_resume(C.thread_act_t(port)); kr != C.KERN_SUCCESS && kr != C.KERN_TERMINATED && kr != C.KERN_INVALID_RIGHT {\n        return fmt.Errorf(\"could not resume task: mach error %d\", kr)\n    }\n}","handlingStrategy":"try-catch","validationCode":"// verify the task is still alive before attempting per-thread resume\nif err := syscall.Kill(pid, 0); err != nil {\n    // task already dead: skip thread_resume loop entirely\n    return nil\n}","typeGuard":null,"tryCatchPattern":"err := grp.kill(dbp)\nif err != nil && strings.Contains(err.Error(), \"could not resume task\") {\n    // after SIGKILL a failed thread_resume is usually harmless teardown noise\n    log.Println(\"non-fatal: thread_resume failed during kill\", err)\n    err = nil\n}","preventionTips":["Purge dead thread ports from the thread map when threads terminate","Ignore resume failures on threads after a successful SIGKILL","Check KERN_TERMINATED/KERN_INVALID_RIGHT as acceptable teardown results","Keep SIGKILL and resume logic ordered so a dead task skips the resume loop"],"tags":["darwin","mach","thread-resume","teardown"],"backgroundTag":"mach-thread-resume-failed","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}