{"record":{"id":"d0f62dff4381ff82","repo":"nats-io/nats-server","slug":"short-index-file","errorCode":null,"errorMessage":"short index file","messagePattern":"short index file","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/filestore.go","lineNumber":10172,"sourceCode":"\t\tif n <= 0 {\n\t\t\tbi = -1\n\t\t\treturn -1\n\t\t}\n\t\tbi += n\n\t\treturn ts\n\t}\n\tmb.msgs = readCount()\n\tmb.bytes = readCount()\n\tatomic.StoreUint64(&mb.first.seq, readSeq())\n\tmb.first.ts = readTimeStamp()\n\tatomic.StoreUint64(&mb.last.seq, readSeq())\n\tmb.last.ts = readTimeStamp()\n\tdmapLen := readCount()\n\n\t// Check if this is a short write index file.\n\tif bi < 0 || bi+checksumSize > len(buf) {\n\t\tos.Remove(ifn)\n\t\treturn fmt.Errorf(\"short index file\")\n\t}\n\n\t// Check for consistency if accounting. If something is off bail and we will rebuild.\n\tif mb.msgs != (atomic.LoadUint64(&mb.last.seq)-atomic.LoadUint64(&mb.first.seq)+1)-dmapLen {\n\t\tos.Remove(ifn)\n\t\treturn fmt.Errorf(\"accounting inconsistent\")\n\t}\n\n\t// Checksum\n\tcopy(mb.lchk[0:], buf[bi:bi+checksumSize])\n\tbi += checksumSize\n\n\t// Now check for presence of a delete map\n\tif dmapLen > 0 {\n\t\t// New version is encoded avl seqset.\n\t\tif buf[1] == newVersion {\n\t\t\tdmap, _, err := avl.Decode(buf[bi:])\n\t\t\tif err != nil {","sourceCodeStart":10154,"sourceCodeEnd":10190,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/filestore.go#L10154-L10190","documentation":"Returned when a file-store index file is shorter than the parsed position plus checksum size — i.e. the index file is truncated or was written incompletely (a short write during index creation). The store deletes the index file and returns this error, after which the index is rebuilt from the message block data.","triggerScenarios":"Loading an index where the read position bi is invalid or bi+checksumSize exceeds len(buf), meaning the index buffer ended prematurely (e.g. crash mid-index-write leaving a partial file).","commonSituations":"Power loss or kill -9 during index file creation, disk-full during index write, or corrupted/truncated files after storage failures.","solutions":["Retry/restart — the truncated index file is removed automatically and rebuilt from block data.","Check for past disk-full events or unclean shutdowns in server logs.","If index rebuilds fail repeatedly, verify filesystem integrity (fsck) and disk health.","Ensure clean shutdowns (SIGTERM/SIGINT, not SIGKILL) to avoid partial index writes."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"short index file\") {\n    // truncated index removed and rebuilt; verify subsequent reads succeed\n}","preventionTips":["Ensure sufficient disk space so index writes never truncate.","Shut down cleanly; avoid kill -9 and power loss (use UPS).","Run filesystem checks if truncation recurs.","Alert on index-rebuild log lines as an early corruption signal."],"tags":["filestore","index","corruption","truncated","go"],"backgroundTag":"truncated-index-file","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}