{"record":{"id":"4819ecd96fb9a072","repo":"nats-io/nats-server","slug":"filestore-max-block-size-is-s","errorCode":null,"errorMessage":"filestore max block size is %s","messagePattern":"filestore max block size is (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/filestore.go","lineNumber":424,"sourceCode":"}\n\nfunc newFileStoreWithCreated(fcfg FileStoreConfig, cfg StreamConfig, created time.Time, prf, oldprf keyGen) (fs *fileStore, err error) {\n\treturn newFileStoreWithCreatedAndMode(fcfg, cfg, created, prf, oldprf, false)\n}\n\nfunc newFileStoreWithCreatedAndMode(fcfg FileStoreConfig, cfg StreamConfig, created time.Time, prf, oldprf keyGen, recovering bool) (fs *fileStore, err error) {\n\tif cfg.Name == _EMPTY_ {\n\t\treturn nil, fmt.Errorf(\"name required\")\n\t}\n\tif cfg.Storage != FileStorage {\n\t\treturn nil, fmt.Errorf(\"fileStore requires file storage type in config\")\n\t}\n\t// Default values.\n\tif fcfg.BlockSize == 0 {\n\t\tfcfg.BlockSize = dynBlkSize(cfg.Retention, cfg.MaxBytes, prf != nil)\n\t}\n\tif fcfg.BlockSize > maxBlockSize {\n\t\treturn nil, fmt.Errorf(\"filestore max block size is %s\", friendlyBytes(maxBlockSize))\n\t}\n\tif fcfg.CacheExpire == 0 {\n\t\tfcfg.CacheExpire = defaultCacheBufferExpiration\n\t}\n\tif fcfg.SubjectStateExpire == 0 {\n\t\tfcfg.SubjectStateExpire = defaultFssExpiration\n\t}\n\tif fcfg.SyncInterval == 0 {\n\t\tfcfg.SyncInterval = defaultSyncInterval\n\t}\n\tdios := fcfg.srv.diskIOSemaphore()\n\n\t// Check the directory\n\tif stat, err := os.Stat(fcfg.StoreDir); os.IsNotExist(err) {\n\t\tif err := os.MkdirAll(fcfg.StoreDir, defaultDirPerms); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"could not create storage directory - %v\", err)\n\t\t}\n\t} else if stat == nil || !stat.IsDir() {","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/filestore.go#L406-L442","documentation":"The file store rejects a FileStoreConfig.BlockSize larger than the compiled-in maxBlockSize limit. The error message includes the human-friendly maximum (friendlyBytes(maxBlockSize)). This guards against allocating file blocks the format cannot support.","triggerScenarios":"Setting FileStoreConfig.BlockSize above maxBlockSize when constructing the file store (server/filestore.go:424), e.g. BlockSize of several GB or an unvalidated value from user config.","commonSituations":"Operator-supplied block size values passed through without clamping; unit mistakes (bytes vs MB/GB) in config files; tuning attempts that exceed the library's hard cap.","solutions":["Lower BlockSize to at most maxBlockSize (see the limit reported in the error message)","Remove the explicit BlockSize so dynBlkSize computes a valid default","Clamp user-provided values against maxBlockSize before building FileStoreConfig"],"exampleFix":"// before\nfcfg := FileStoreConfig{BlockSize: 16 << 30}\nfs, err := newFileStoreWithCreatedAndMode(fcfg, cfg, time.Now(), nil, nil, false)\n// after\nfcfg := FileStoreConfig{BlockSize: 8 << 20}\nif fcfg.BlockSize > maxBlockSize {\n    fcfg.BlockSize = maxBlockSize\n}\nfs, err := newFileStoreWithCreatedAndMode(fcfg, cfg, time.Now(), nil, nil, false)","handlingStrategy":"validation","validationCode":"if fcfg.BlockSize > maxBlockSize {\n    return fmt.Errorf(\"BlockSize %d exceeds max %s\", fcfg.BlockSize, friendlyBytes(maxBlockSize))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp operator-supplied BlockSize against the library max","Prefer omitting BlockSize and letting dynBlkSize pick a default","Watch for byte/MB unit mistakes in config files"],"tags":["jetstream","filestore","config-limit","go"],"backgroundTag":"config-limit-exceeded","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}