nats-io/nats-server · error
Error creating msg block file: %v
Error message
Error creating msg block file: %v
What it means
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.
Source
Thrown at server/filestore.go:5177
// Now do local hash.
key := sha256.Sum256(fs.hashKeyForBlock(index))
hh, err := highwayhash.NewDigest64(key[:])
if err != nil {
return nil, fmt.Errorf("could not create hash: %v", err)
}
mb.hh = hh
fs.dios.acquire()
mfd, err := os.OpenFile(mb.mfn, os.O_CREATE|os.O_RDWR, defaultFilePerms)
fs.dios.release()
if err != nil {
if isPermissionError(err) {
return nil, err
}
_ = mb.dirtyCloseWithRemove(true)
return nil, fmt.Errorf("Error creating msg block file: %v", err)
}
mb.mfd = mfd
// Check if encryption is enabled.
if fs.prf != nil {
if err := fs.genEncryptionKeysForBlock(mb); err != nil {
return nil, err
}
}
// If we know we will need this so go ahead and spin up.
if !fs.fip {
mb.spinUpFlushLoop()
}
// Add to our list of blocks and mark as last.
fs.addMsgBlock(mb)
View on GitHub (pinned to 3a66a489d2)
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
Defensive patterns
Strategy: try-catch
Validate before calling
// Before starting/creating streams, verify the store dir is writable and has space
info, err := os.Stat(storeDir)
if err != nil || !info.IsDir() {
return fmt.Errorf("store dir missing: %s", storeDir)
}
probe := filepath.Join(storeDir, ".probe")
if err := os.WriteFile(probe, []byte("x"), 0600); err != nil {
return fmt.Errorf("store dir not writable: %v", err)
}
os.Remove(probe) Try / catch
// Go: distinguish permission errors from other OS failures
if _, err := createMsgBlock(fs, index); err != nil {
if isPermissionError(err) {
// fix ownership/permissions on store_dir
}
return err
} Prevention
- 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
When it happens
Trigger: Creating a new message block on a file-store stream when the data directory is unwritable, full, or the process has exhausted file descriptors.
Common situations: 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.
Understand the failure class
Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.
Related errors
- failed to write to temporary file: %w
- short write to temporary file (%d != %d)
- failed to close temporary file: %w
- could not create consumer directory - %v
- could not create storage directory - %v
AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02).
Data as JSON: /api/errors/0294911934a6981d.
Report an issue: GitHub.