{"record":{"id":"48feb2e2799c7b3f","repo":"grpc/grpc-go","slug":"failed-to-create-default-buffer-pool-v","errorCode":null,"errorMessage":"Failed to create default buffer pool: %v","messagePattern":"Failed to create default buffer pool: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"mem/buffer_pool.go","lineNumber":56,"sourceCode":"\tPut(*[]byte)\n}\n\nvar (\n\tdefaultBufferPoolSizeExponents = []uint8{\n\t\t8,\n\t\t12, // Go page size, 4KB\n\t\t14, // 16KB (max HTTP/2 frame size used by gRPC)\n\t\t15, // 32KB (default buffer size for io.Copy)\n\t\t20, // 1MB\n\t}\n\tdefaultBufferPool BufferPool\n)\n\nfunc init() {\n\tvar err error\n\tdefaultBufferPool, err = NewBinaryTieredBufferPool(defaultBufferPoolSizeExponents...)\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"Failed to create default buffer pool: %v\", err))\n\t}\n\n\tinternal.SetDefaultBufferPool = func(pool BufferPool) {\n\t\tdefaultBufferPool = pool\n\t}\n\n\tinternal.SetBufferPoolingThresholdForTesting = func(threshold int) {\n\t\tbufferPoolingThreshold = threshold\n\t}\n}\n\n// DefaultBufferPool returns the current default buffer pool. It is a BufferPool\n// created with NewBufferPool that uses a set of default sizes optimized for\n// expected workflows.\nfunc DefaultBufferPool() BufferPool {\n\treturn defaultBufferPool\n}\n","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/grpc/grpc-go/blob/0c51461d27177d997e14c642fe18c11668fc09a3/mem/buffer_pool.go#L38-L74","documentation":"The mem package init() (mem/buffer_pool.go:52-57) builds the process-wide default BufferPool from the hardcoded defaultBufferPoolSizeExponents ([8,12,14,15,20]) via NewBinaryTieredBufferPool. If that constructor returns an error (invalid, duplicate, or out-of-range power-of-two exponents, or an empty list), init panics because the package cannot operate without a pool. This is a startup-time, fail-fast guard.","triggerScenarios":"Not triggerable by normal callers with stock grpc-go. Fires only if the internal exponent list becomes invalid (library regression), if the underlying internal/mem.NewBinaryTieredBufferPool validation rules change, or if a fork edits defaultBufferPoolSizeExponents to bad values (e.g. duplicates like [8,8] or values >30).","commonSituations":"Forking/patching the mem package and editing defaultBufferPoolSizeExponents; a go.mod `replace` directive pointing grpc-go to a broken fork or commit; using a corrupted or in-development build where the internal constructor's validation rejects the defaults.","solutions":["Use an unmodified, released grpc-go; remove any go.mod `replace google.golang.org/grpc => ...` that points to a fork.","If you forked mem and changed defaultBufferPoolSizeExponents, keep them distinct, non-empty, and within the valid power-of-two exponent range.","Construct your own pool with mem.NewBinaryTieredBufferPool and inspect its error; do not rely on overriding the package default in production (internal.SetDefaultBufferPool is for tests)."],"exampleFix":"// Not caller code; this is the library's own init.\n// If you forked mem/buffer_pool.go and broke the defaults, restore them:\n//   var defaultBufferPoolSizeExponents = []uint8{8, 12, 14, 15, 20}\n//\n// If you need a custom pool in your app, build it explicitly and pass it via\n// dial/server options; do NOT edit the package-level default.","handlingStrategy":"validation","validationCode":"// The panic is in mem.init(); callers cannot intercept it. Validate your own\n// pool construction explicitly instead of relying on overrides:\nfunc buildPool(exps ...uint8) (mem.BufferPool, error) {\n    return mem.NewBinaryTieredBufferPool(exps...)\n}\n// Usage:\n//   p, err := buildPool(8, 12, 14, 15, 20)\n//   if err != nil { log.Fatal(err) }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use unmodified, released grpc-go; remove go.mod `replace` directives that point to forks.","If you fork mem, keep defaultBufferPoolSizeExponents distinct and within the valid exponent range.","Build and inspect your own pool with NewBinaryTieredBufferPool rather than editing the package default."],"tags":["mem","buffer-pool","init","panic","go"],"backgroundTag":null,"analyzedSha":"0c51461d27177d997e14c642fe18c11668fc09a3","analyzedAt":"2026-08-11T14:49:15.055Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}