nats-io/nats-server · critical
short write to temporary file (%d != %d)
Error message
short write to temporary file (%d != %d)
What it means
Returned when a write to the temporary block file completed without error but wrote fewer bytes than the buffer length (short write). The file store treats this as a failed update and aborts via errorCleanup, leaving the original block file intact.
Source
Thrown at server/filestore.go:8064
// writing metadata.
meta := &CompressionInfo{
Algorithm: alg,
OriginalSize: uint64(originalSize),
}
buf = append(meta.MarshalMetadata(), buf...)
}
// Re-encrypt the block if necessary.
if err = mb.encryptOrDecryptIfNeeded(buf); err != nil {
return errorCleanup(err)
}
// Write the new block data (which might be compressed or encrypted) to the
// temporary file.
if n, err := tmpFD.Write(buf); err != nil {
return errorCleanup(fmt.Errorf("failed to write to temporary file: %w", err))
} else if n != len(buf) {
return errorCleanup(fmt.Errorf("short write to temporary file (%d != %d)", n, len(buf)))
}
if err := tmpFD.Sync(); err != nil {
return errorCleanup(fmt.Errorf("failed to sync temporary file: %w", err))
}
if err := tmpFD.Close(); err != nil {
return errorCleanup(fmt.Errorf("failed to close temporary file: %w", err))
}
// Now replace the original file with the newly updated temp file.
if err := os.Rename(tmpFN, origFN); err != nil {
return fmt.Errorf("failed to move temporary file into place: %w", err)
}
// Since the message block might be retained in memory, make sure the
// compression algorithm is up-to-date, since this will be needed when
// compacting or truncating.
mb.cmp = alg
View on GitHub (pinned to 3a66a489d2)
Solutions
- Move the JetStream store onto a reliable local filesystem (ext4/xfs), not network mounts.
- Check disk quotas (quota -s) on the storage volume.
- Inspect storage subsystem logs for partial-write/IO errors.
- Retry the operation; the temp file is cleaned up automatically.
Example fix
// before: store on NFS mount StoreDir: /mnt/nfs/jetstream // after: local disk StoreDir: /var/lib/nats/jetstream
Defensive patterns
Strategy: fallback
Try / catch
if err != nil && strings.Contains(err.Error(), "short write to temporary file") {
// treat storage as unreliable; migrate store to local disk, alert ops
} Prevention
- Run JetStream on local ext4/xfs, never NFS/SMB/CIFS.
- Check disk quotas on the storage volume.
- Validate storage reliability under load before production.
- Monitor partial-write and storage errors in dmesg/syslog.
When it happens
Trigger: tmpFD.Write(buf) returns n != len(buf) during a file-store message block update — a partial write of the compressed/encrypted block buffer.
Common situations: Underlying storage returning partial writes (NFS/CIFS mounts, iSCSI issues), disk quotas silently truncating writes, or extremely large block buffers on unreliable storage.
Related errors
- failed to write to temporary file: %w
- failed to close temporary file: %w
- failed to sync temporary file: %w
- failed to move temporary file into place: %w
- fileStore requires file storage type in config
AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02).
Data as JSON: /api/errors/a217caf3f1c130a4.
Report an issue: GitHub.