{"record":{"id":"a0dc3ae5dd2095e6","repo":"golang/go","slug":"failed-to-find-matching-goroutines-for-name-s","errorCode":null,"errorMessage":"failed to find matching goroutines for name: %s","messagePattern":"failed to find matching goroutines for name: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/trace/pprof.go","lineNumber":60,"sourceCode":"\t}\n}\n\n// pprofMatchingGoroutines returns the ids of goroutines of the matching name and its interval.\n// If the id string is empty, returns nil without an error.\nfunc pprofMatchingGoroutines(name string, t *parsedTrace) (map[trace.GoID][]interval, error) {\n\tres := make(map[trace.GoID][]interval)\n\tfor _, g := range t.summary.Goroutines {\n\t\tif name != \"\" && g.Name != name {\n\t\t\tcontinue\n\t\t}\n\t\tendTime := g.EndTime\n\t\tif g.EndTime == 0 {\n\t\t\tendTime = t.endTime() // Use the trace end time, since the goroutine is still live then.\n\t\t}\n\t\tres[g.ID] = []interval{{start: g.StartTime, end: endTime}}\n\t}\n\tif len(res) == 0 {\n\t\treturn nil, fmt.Errorf(\"failed to find matching goroutines for name: %s\", name)\n\t}\n\treturn res, nil\n}\n\n// pprofMatchingRegions returns the time intervals of matching regions\n// grouped by the goroutine id. If the filter is nil, returns nil without an error.\nfunc pprofMatchingRegions(filter *regionFilter, t *parsedTrace) (map[trace.GoID][]interval, error) {\n\tif filter == nil {\n\t\treturn nil, nil\n\t}\n\n\tgToIntervals := make(map[trace.GoID][]interval)\n\tfor _, g := range t.summary.Goroutines {\n\t\tfor _, r := range g.Regions {\n\t\t\tif !filter.match(t, r) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tgToIntervals[g.ID] = append(gToIntervals[g.ID], regionInterval(t, r))","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/trace/pprof.go#L42-L78","documentation":"`pprofByGoroutine` filters goroutines by `name` (the function name captured for the goroutine). It returns an error if no goroutine in the trace's summary matches the supplied name. This surfaces inside pprof region/syscall handlers when a name filter yields nothing.","triggerScenarios":"Passing a goroutine name via the viewer/programmatic API that does not match any `g.Name` in `t.summary.Goroutines`; typos in the function name; names that include receiver types or package paths the user didn't include; anonymized/unnamed goroutines (name == \"\").","commonSituations":"Filtering a trace by `main.worker` when the goroutine was actually `runtime/pprof.Do`-named or had no name; forgetting the full path like `github.com/x/y/pkg.foo`; querying a trace where the goroutine launched but never executed user code to get a name.","solutions":["Open the trace in the viewer's goroutine view and copy the exact name string shown, then filter with that.","If you want all goroutines, pass an empty name (the `name != \"\"` guard skips filtering).","Ensure the goroutine was named via `runtime/trace.WithRegion`/`runtime/pprof` or that it ran named user code so the runtime could capture a name."],"exampleFix":"// before\nname := \"worker\"        // matches nothing\n// after\nname := \"main.runWorker\" // exact name from summary","handlingStrategy":"validation","validationCode":"names := map[string]bool{}\nfor _, g := range t.summary.Goroutines { names[g.Name] = true }\nif name != \"\" && !names[name] {\n    return fmt.Errorf(\"no goroutine named %q; known: %v\", name, names)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Copy goroutine names exactly from the viewer's goroutine page.","Pass an empty name to select all goroutines."],"tags":["go-tool-trace","pprof","goroutine","filter"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}