{"record":{"id":"e630bf9e0bead00e","repo":"go-delve/delve","slug":"unknown-goroutine-d","errorCode":null,"errorMessage":"unknown goroutine %d","messagePattern":"unknown goroutine (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/variables.go","lineNumber":413,"sourceCode":"\t\t//    to avoid reading any other goroutine and, more importantly, (b) we\n\t\t//    could be reading an incorrect value for the goroutine ID of a thread.\n\t\t//    This condition usually happens when a goroutine calls runtime.clone\n\t\t//    and for a short period of time two threads will appear to be running\n\t\t//    the same goroutine.\n\t\t// 3. if the caller asks for gid == 0 and the selected goroutine is\n\t\t//    either 0 or nil.\n\t\t//    Goroutine 0 is special, it either means we have no current goroutine\n\t\t//    (for example, running C code), or that we are running on a special\n\t\t//    stack (system stack, signal handling stack) and we didn't properly\n\t\t//    detect it.\n\t\t//    Since there could be multiple goroutines '0' running simultaneously\n\t\t//    if the user requests it return the one that's already selected or\n\t\t//    nil if there isn't a selected goroutine.\n\t\treturn selg, nil\n\t}\n\n\tif gid == 0 {\n\t\treturn nil, fmt.Errorf(\"unknown goroutine %d\", gid)\n\t}\n\n\tif g := dbp.gcache.partialGCache[gid]; g != nil {\n\t\treturn g, nil\n\t}\n\n\t// Calling GoroutinesInfo could be slow if there are many goroutines\n\t// running, check if a running goroutine has been requested first.\n\tfor _, thread := range dbp.ThreadList() {\n\t\tg, _ := GetG(thread)\n\t\tif g != nil && g.ID == gid {\n\t\t\treturn g, nil\n\t\t}\n\t}\n\n\tconst goroutinesInfoLimit = 10\n\tnextg := 0\n\tfor nextg >= 0 {","sourceCodeStart":395,"sourceCodeEnd":431,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/variables.go#L395-L431","documentation":"FindGoroutine resolves a goroutine ID to a *G using the partial and full goroutine caches plus runtime scans. Goroutine ID 0 is special: it is never a valid user goroutine, so requesting it explicitly (while not falling into the 'return selected' case) yields this error. The caller passed a goroutine identifier the debugger cannot resolve.","triggerScenarios":"Calling debugger.ConvertEvalScope (or any API that reaches proc.FindGoroutine) with gid == 0, e.g. an RPC EvalScope/Command with GoroutineID=0 on a target whose API contract expects a positive goroutine ID.","commonSituations":"IDE/DAP clients sending GoroutineID 0 for 'current goroutine' when the server-side convention instead expects -1 (any) or the actual selected ID; scripts that default an unset variable to 0.","solutions":["Pass the actual target goroutine ID (positive integer) obtained from State()/ListGoroutines.","Use GoroutineID = -1 (meaning 'use current/selected goroutine') instead of 0 for the non-specific case.","Verify the goroutine still exists; re-fetch the goroutine list since IDs become invalid after exit."],"exampleFix":"// before\nscope, err := debugger.ConvertEvalScope(target, 0, frame, 0)\n\n// after\ngid := -1 // or a real goroutine ID from state.CurrentThread goroutine\nscope, err := debugger.ConvertEvalScope(target, gid, frame, 0)","handlingStrategy":"validation","validationCode":"if gid == 0 {\n    gid = -1 // sentinel: use currently selected goroutine\n}\nif gid > 0 {\n    found := false\n    for _, g := range goroutineList { if g.ID == gid { found = true; break } }\n    if !found { return fmt.Errorf(\"goroutine %d not in current list\", gid) }\n}","typeGuard":null,"tryCatchPattern":"scope, err := client.ConvertEvalScope(pid, gid, frame, 0)\nif err != nil && strings.Contains(err.Error(), \"unknown goroutine\") {\n    state, _ := client.GetState()\n    gid = state.SelectedGoroutine.ID\n    scope, err = client.ConvertEvalScope(pid, gid, frame, 0)\n}","preventionTips":["Never pass 0 as a goroutine ID; use -1 for 'current'","Fetch goroutine IDs from ListGoroutines/GetState, never hard-code","Validate IDs against a freshly fetched goroutine list"],"tags":["go","debugger","goroutines"],"backgroundTag":"unknown-goroutine-id","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}