grpc/grpc-go · error · errorNilServer
profiling: no grpc.Server provided
Error message
profiling: no grpc.Server provided
What it means
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.
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 03255a9237)
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.
Example fix
// before
profiling.Init(&profiling.ProfilingConfig{
Enabled: true, StreamStatsSize: 1000, // Server nil
})
// after
srv := grpc.NewServer()
profiling.Init(&profiling.ProfilingConfig{
Enabled: true, StreamStatsSize: 1000, Server: srv,
}) Defensive patterns
Strategy: validation
Validate before calling
if pc.Server == nil {
return errors.New("profiling requires a non-nil grpc.Server")
} Try / catch
if err := profiling.Init(pc); err != nil {
if errors.Is(err, profiling.ErrorNilServer) /* or string match */ {
return fmt.Errorf("create the server first: %w", err)
}
} Prevention
- Construct grpc.NewServer() before building the ProfilingConfig.
- Skip profiling.Init in client-only processes.
- Always set ProfilingConfig.Server explicitly.
When it happens
Trigger: Calling profiling.Init(&ProfilingConfig{Enabled: true, StreamStatsSize: 100}) without setting the Server field; passing a config built before the server is constructed.
Common situations: 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.
Related errors
- missing server_listener_resource_name_template in the bootst
- authz: authorization policy file path is empty
- authz: requires refresh interval(%v) greater than 0s
- policyFile(%s) read failed: %v
- randomsubsetting: json.Unmarshal failed for configuration: %
AI-assisted analysis of grpc/grpc-go@03255a9237 (2026-08-07).
Data as JSON: /api/errors/84374e432af8a7fe.
Report an issue: GitHub.