{"record":{"id":"0294911934a6981d","repo":"nats-io/nats-server","slug":"error-creating-msg-block-file-v","errorCode":null,"errorMessage":"Error creating msg block file: %v","messagePattern":"Error creating msg block file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/filestore.go","lineNumber":5177,"sourceCode":"\n\t// Now do local hash.\n\tkey := sha256.Sum256(fs.hashKeyForBlock(index))\n\thh, err := highwayhash.NewDigest64(key[:])\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"could not create hash: %v\", err)\n\t}\n\tmb.hh = hh\n\n\tfs.dios.acquire()\n\tmfd, err := os.OpenFile(mb.mfn, os.O_CREATE|os.O_RDWR, defaultFilePerms)\n\tfs.dios.release()\n\n\tif err != nil {\n\t\tif isPermissionError(err) {\n\t\t\treturn nil, err\n\t\t}\n\t\t_ = mb.dirtyCloseWithRemove(true)\n\t\treturn nil, fmt.Errorf(\"Error creating msg block file: %v\", err)\n\t}\n\tmb.mfd = mfd\n\n\t// Check if encryption is enabled.\n\tif fs.prf != nil {\n\t\tif err := fs.genEncryptionKeysForBlock(mb); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\n\t// If we know we will need this so go ahead and spin up.\n\tif !fs.fip {\n\t\tmb.spinUpFlushLoop()\n\t}\n\n\t// Add to our list of blocks and mark as last.\n\tfs.addMsgBlock(mb)\n","sourceCodeStart":5159,"sourceCodeEnd":5195,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/filestore.go#L5159-L5195","documentation":"Thrown when os.OpenFile fails to create/open the message block's backing data file (mb.mfn) during block creation. The block is torn down with dirtyCloseWithRemove(true) and the underlying OS error (e.g. permission denied, no space, too many open files) is wrapped in this message.","triggerScenarios":"Creating a new message block on a file-store stream when the data directory is unwritable, full, or the process has exhausted file descriptors.","commonSituations":"Wrong ownership/permissions on the store_dir, disk full after storage limits hit, ulimit -n too low for streams with many blocks, read-only mount after host recovery.","solutions":["Check store_dir permissions/ownership for the jetstream user and fix them","Free disk space or raise storage limits ( DiskCapacity check)","Increase the open-file limit (ulimit -n / systemd LimitNOFILE)","Check isPermissionError in the wrapped cause to distinguish permission vs other OS failures"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Before starting/creating streams, verify the store dir is writable and has space\ninfo, err := os.Stat(storeDir)\nif err != nil || !info.IsDir() {\n    return fmt.Errorf(\"store dir missing: %s\", storeDir)\n}\nprobe := filepath.Join(storeDir, \".probe\")\nif err := os.WriteFile(probe, []byte(\"x\"), 0600); err != nil {\n    return fmt.Errorf(\"store dir not writable: %v\", err)\n}\nos.Remove(probe)","typeGuard":null,"tryCatchPattern":"// Go: distinguish permission errors from other OS failures\nif _, err := createMsgBlock(fs, index); err != nil {\n    if isPermissionError(err) {\n        // fix ownership/permissions on store_dir\n    }\n    return err\n}","preventionTips":["Pre-provision store_dir with correct ownership/permissions","Set LimitNOFILE/ulimit -n generously for many-block streams","Monitor free disk space and DiskCapacity limits","Avoid read-only remounts; mount store volumes rw"],"tags":["filesystem","io","permissions","filestore"],"backgroundTag":"file-open-failed","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}