{"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":null,"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/0c51461d27177d997e14c642fe18c11668fc09a3/profiling/service/service.go#L43-L79","documentation":"Returned by profiling.Init when the supplied ProfilingConfig has a nil Server field. The profiling package needs a *grpc.Server to register its ProfilingService handler on; without one there is no way to expose the profiling RPCs, so Init bails out before initializing stats.","triggerScenarios":"Calling profiling.Init(&profiling.ProfilingConfig{Enabled: true, StreamStatsSize: 1000}) without setting Server. Common when an app constructs the config before the *grpc.Server is created and forgets to wire it back.","commonSituations":"Order-of-initialization bug: profiling.Init invoked before grpc.NewServer. Refactor that introduced a NewProfilingConfig helper that never receives the server. Test code that wants stats but not the RPC service.","solutions":["Create the *grpc.Server first, then pass it: profiling.Init(&profiling.ProfilingConfig{Server: s, Enabled: true, StreamStatsSize: N}).","If you only want in-process stats and not the RPC service, note that this package requires a server; call internal/profiling directly instead.","Guard with a nil check so the program logs and continues rather than returning a hard error during startup."],"exampleFix":"// before\nprofiling.Init(&profiling.ProfilingConfig{Enabled: true, StreamStatsSize: 1024})\n// after\ns := grpc.NewServer()\nprofiling.Init(&profiling.ProfilingConfig{Enabled: true, StreamStatsSize: 1024, Server: s})","handlingStrategy":"validation","validationCode":"if pc.Server == nil {\n    log.Printf(\"skipping profiling.Init: no grpc.Server provided\")\n    return\n}\nif err := profiling.Init(pc); err != nil { log.Fatal(err) }","typeGuard":null,"tryCatchPattern":"if err := profiling.Init(pc); err != nil { if errors.Is(err, service.ErrorNilServer) { /* server was nil; init order bug */ log.Printf(\"profiling not started: %v\", err) } else { return err } }","preventionTips":["Always construct *grpc.Server before profiling.Init.","Wire profiling.Init in the same function that calls RegisterService to keep ordering obvious.","Add a unit test asserting profiling.Init fails fast when Server is nil (documented contract)."],"tags":["profiling","grpc-server","init","config"],"backgroundTag":null,"analyzedSha":"0c51461d27177d997e14c642fe18c11668fc09a3","analyzedAt":"2026-08-11T14:49:15.055Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}