grpc/grpc-go · error
profiling: no grpc.Server provided
Error message
profiling: no grpc.Server provided
What it means
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.
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.
Example fix
// before
profiling.Init(&profiling.ProfilingConfig{Enabled: true, StreamStatsSize: 1024})
// after
s := grpc.NewServer()
profiling.Init(&profiling.ProfilingConfig{Enabled: true, StreamStatsSize: 1024, Server: s}) Defensive patterns
Strategy: validation
Validate before calling
if pc.Server == nil {
log.Printf("skipping profiling.Init: no grpc.Server provided")
return
}
if err := profiling.Init(pc); err != nil { log.Fatal(err) } Try / catch
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 } } Prevention
- 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).
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- could not get resolver for default scheme
- "allow_rules" is not present
- "allow_rules
- authz: authorization policy file path is empty
- authz: requires refresh interval
AI-assisted analysis of grpc/grpc-go@0c51461d27 (2026-08-11).
Data as JSON: /api/errors/84374e432af8a7fe.
Report an issue: GitHub.
Appendix: source
Thrown at profiling/service/service.go:61
// ProfilingConfig defines configuration options for the Init method.
type ProfilingConfig struct {
// Setting this to true will enable profiling.
Enabled bool
// Profiling uses a circular buffer (ring buffer) to store statistics for
// only the last few RPCs so that profiling stats do not grow unbounded. This
// parameter defines the upper limit on the number of RPCs for which
// statistics should be stored at any given time. An average RPC requires
// approximately 2-3 KiB of memory for profiling-related statistics, so
// choose an appropriate number based on the amount of memory you can afford.
StreamStatsSize uint32
// To expose the profiling service and its methods, a *grpc.Server must be
// provided.
Server *grpc.Server
}
var errorNilServer = errors.New("profiling: no grpc.Server provided")
// Init takes a *ProfilingConfig to initialize profiling (turned on/off
// depending on the value set in pc.Enabled) and register the profiling service
// in the server provided in pc.Server.
func Init(pc *ProfilingConfig) error {
if pc.Server == nil {
return errorNilServer
}
if err := profiling.InitStats(pc.StreamStatsSize); err != nil {
return err
}
ppb.RegisterProfilingServer(pc.Server, getProfilingServerInstance())
// Do this last after everything has been initialized and allocated.
profiling.Enable(pc.Enabled)
View on GitHub (pinned to 0c51461d27)