{"record":{"id":"84374e432af8a7fe","repo":"grpc/grpc-go","slug":"profiling-no-grpc-server-provided","errorCode":null,"errorMessage":"profiling: no grpc.Server provided","messagePattern":"profiling: no grpc\\.Server provided","errorType":"validation","errorClass":"errorNilServer","httpStatus":null,"severity":"error","filePath":"profiling/service/service.go","lineNumber":61,"sourceCode":"// ProfilingConfig defines configuration options for the Init method.\ntype ProfilingConfig struct {\n\t// Setting this to true will enable profiling.\n\tEnabled bool\n\n\t// Profiling uses a circular buffer (ring buffer) to store statistics for\n\t// only the last few RPCs so that profiling stats do not grow unbounded. This\n\t// parameter defines the upper limit on the number of RPCs for which\n\t// statistics should be stored at any given time. An average RPC requires\n\t// approximately 2-3 KiB of memory for profiling-related statistics, so\n\t// choose an appropriate number based on the amount of memory you can afford.\n\tStreamStatsSize uint32\n\n\t// To expose the profiling service and its methods, a *grpc.Server must be\n\t// provided.\n\tServer *grpc.Server\n}\n\nvar errorNilServer = errors.New(\"profiling: no grpc.Server provided\")\n\n// Init takes a *ProfilingConfig to initialize profiling (turned on/off\n// depending on the value set in pc.Enabled) and register the profiling service\n// in the server provided in pc.Server.\nfunc Init(pc *ProfilingConfig) error {\n\tif pc.Server == nil {\n\t\treturn errorNilServer\n\t}\n\n\tif err := profiling.InitStats(pc.StreamStatsSize); err != nil {\n\t\treturn err\n\t}\n\n\tppb.RegisterProfilingServer(pc.Server, getProfilingServerInstance())\n\n\t// Do this last after everything has been initialized and allocated.\n\tprofiling.Enable(pc.Enabled)\n","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/grpc/grpc-go/blob/03255a9237b6eb32710f6bc4f2de9a675b99fe36/profiling/service/service.go#L43-L79","documentation":"Returned by profiling.Init (profiling/service/service.go:61, used at 67-69) when ProfilingConfig.Server is nil. The profiling package must register its ProfilingServer service on a *grpc.Server, so a nil server makes initialization meaningless and is rejected.","triggerScenarios":"Calling profiling.Init(&ProfilingConfig{Enabled: true, StreamStatsSize: 100}) without setting the Server field; passing a config built before the server is constructed.","commonSituations":"Building the ProfilingConfig before grpc.NewServer and forgetting to assign it; wiring profiling in a test without a real server; conditional profiling code path that skips server creation.","solutions":["Set ProfilingConfig.Server to your *grpc.Server before calling profiling.Init.","Ensure grpc.NewServer() runs and returns a non-nil server prior to profiling setup.","Skip profiling.Init entirely if you have no server (e.g. client-only process).","Guard with: if pc.Server == nil { return errors.New(...) } with a clearer message."],"exampleFix":"// before\nprofiling.Init(&profiling.ProfilingConfig{\n    Enabled: true, StreamStatsSize: 1000, // Server nil\n})\n\n// after\nsrv := grpc.NewServer()\nprofiling.Init(&profiling.ProfilingConfig{\n    Enabled: true, StreamStatsSize: 1000, Server: srv,\n})","handlingStrategy":"validation","validationCode":"if pc.Server == nil {\n    return errors.New(\"profiling requires a non-nil grpc.Server\")\n}","typeGuard":null,"tryCatchPattern":"if err := profiling.Init(pc); err != nil {\n    if errors.Is(err, profiling.ErrorNilServer) /* or string match */ {\n        return fmt.Errorf(\"create the server first: %w\", err)\n    }\n}","preventionTips":["Construct grpc.NewServer() before building the ProfilingConfig.","Skip profiling.Init in client-only processes.","Always set ProfilingConfig.Server explicitly."],"tags":["go","grpc","profiling","config"],"analyzedSha":"03255a9237b6eb32710f6bc4f2de9a675b99fe36","analyzedAt":"2026-08-07T00:29:34.215Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}