{"record":{"id":"bb2cbf0f673251e6","repo":"nats-io/nats-server","slug":"error-decoding-sources-state-s","errorCode":null,"errorMessage":"Error decoding sources state: %s","messagePattern":"Error decoding sources state: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/filestore.go","lineNumber":12487,"sourceCode":"}\n\n// Lock should be held.\nfunc (fs *fileStore) recoverSourcesState() uint64 {\n\t// See if we have a sources index file.\n\tfs.dios.acquire()\n\tfn := fs.sourcesStatePath()\n\tbuf, err := os.ReadFile(fn)\n\tfs.dios.release()\n\n\tif err != nil && !os.IsNotExist(err) {\n\t\tfs.warn(\"Recovering sources state from index errored: %v\", err)\n\t}\n\n\tvar sourcesSeq uint64\n\tif err == nil {\n\t\tsourcesSeq, err = fs.decodeSourcesState(buf)\n\t\tif err != nil {\n\t\t\tfs.warn(\"Error decoding sources state: %s\", err)\n\t\t\t// Remove the file, and reset collected state (if any).\n\t\t\t_ = os.Remove(fn)\n\t\t\tfs.sources = nil\n\t\t}\n\t}\n\n\tif sourcesSeq < fs.state.FirstSeq {\n\t\tsourcesSeq = fs.state.FirstSeq\n\t}\n\treturn sourcesSeq\n}\n\nvar errSourcesInvalidVersion = errors.New(\"sources: encoded version not known\")\n\nfunc (fs *fileStore) decodeSourcesState(b []byte) (uint64, error) {\n\tif len(b) < sourcesHeaderLen {\n\t\treturn 0, io.ErrShortBuffer\n\t}","sourceCodeStart":12469,"sourceCodeEnd":12505,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/filestore.go#L12469-L12505","documentation":"A warning logged by recoverSourcesState() when the sources index file exists but fails to decode. The file is deleted and in-memory sources state reset, so recovery continues with sources sequence tracking restarted rather than failing stream startup.","triggerScenarios":"Thrown at server/filestore.go:12487 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["The corrupt file is removed automatically; verify it regenerates on next run","Check the store directory for disk corruption or version-format mismatch","Re-sync mirror/source streams if sequence continuity was lost"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}