{"record":{"id":"53c11574840a1763","repo":"VictoriaMetrics/VictoriaMetrics","slug":"cannot-seek-to-offset-d-for-q-w","errorCode":null,"errorMessage":"cannot seek to offset=%d for %q: %w","messagePattern":"cannot seek to offset=(.+?) for %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/filestream/filestream.go","lineNumber":84,"sourceCode":"\tf  *os.File\n\tbr *bufio.Reader\n\tst streamTracker\n}\n\n// Path returns the path to r\nfunc (r *Reader) Path() string {\n\treturn r.f.Name()\n}\n\n// OpenReaderAt opens the file at the given path in nocache mode at the given offset.\n//\n// If nocache is set, then the reader doesn't pollute OS page cache.\nfunc OpenReaderAt(path string, offset int64, nocache bool) (*Reader, error) {\n\tr := MustOpen(path, nocache)\n\tn, err := r.f.Seek(offset, io.SeekStart)\n\tif err != nil {\n\t\tr.MustClose()\n\t\treturn nil, fmt.Errorf(\"cannot seek to offset=%d for %q: %w\", offset, path, err)\n\t}\n\tif n != offset {\n\t\tr.MustClose()\n\t\treturn nil, fmt.Errorf(\"invalid seek offset for %q; got %d; want %d\", path, n, offset)\n\t}\n\treturn r, nil\n}\n\n// MustOpen opens the file from the given path in nocache mode.\n//\n// If nocache is set, then the reader doesn't pollute OS page cache.\nfunc MustOpen(path string, nocache bool) *Reader {\n\tf, err := os.Open(path)\n\tif err != nil {\n\t\tlogger.Panicf(\"FATAL: cannot open file: %s\", err)\n\t}\n\tr := &Reader{\n\t\tf:  f,","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/VictoriaMetrics/VictoriaMetrics/blob/5079fb58f1e8e62113f90c945ad71586c797d770/lib/filestream/filestream.go#L66-L102","documentation":"OpenReaderAt opens a file and seeks to the requested absolute offset before returning the reader. If the underlying f.Seek(offset, io.SeekStart) syscall fails, the file is closed and this wrapped error is returned. It means the OS rejected the seek itself (bad fd, I/O error, or invalid arguments), not that the seek landed elsewhere.","triggerScenarios":"Calling filestream.OpenReaderAt (directly or via NewReadCloser / tryOpeningQueue when opening queue file streams) with a negative offset, or when the opened file cannot be seeked (fd invalid after open failure, I/O error, ESPIPE on non-seekable special files, EIO on failing disks/NFS).","commonSituations":"Queue/persistent-queue code resuming from a stored offset that was serialized as negative or corrupted; files on network mounts or failing storage returning I/O errors during seek; opening non-regular files (pipes/devices) as streams.","solutions":["Check the offset passed in: it must be >= 0 and within the file size; fix the stored/computed offset","Verify the path points to a regular, seekable file, not a pipe/socket/device","Run fsck / check disk and mount health if the wrapped errno is EIO","Retry opening once — transient NFS/EIO seek failures may succeed on a fresh open"],"exampleFix":"// before\noffset := int64(-1) // corrupted persisted offset\nr, err := filestream.OpenReaderAt(path, offset, false)\n// after\nif fi, statErr := os.Stat(path); statErr == nil {\n    if offset < 0 || offset > fi.Size() {\n        offset = 0\n    }\n}\nr, err := filestream.OpenReaderAt(path, offset, false)","handlingStrategy":"validation","validationCode":"fi, err := os.Stat(path)\nif err != nil {\n    return err\n}\nif offset < 0 || offset > fi.Size() {\n    return fmt.Errorf(\"offset %d out of range for %s (size %d)\", offset, path, fi.Size())\n}","typeGuard":"func isSeekableRegularFile(fi os.FileInfo) bool {\n    return fi != nil && fi.Mode().IsRegular()\n}","tryCatchPattern":"r, err := filestream.OpenReaderAt(path, offset, nocache)\nif err != nil && strings.Contains(err.Error(), \"cannot seek to offset\") {\n    // wrapped OS seek error — log the underlying errno and fall back to offset 0\n    r, err = filestream.OpenReaderAt(path, 0, nocache)\n}","preventionTips":["Persist and load queue offsets with checksums so corruption is detected before use","Only open regular files with OpenReaderAt; never pipes/devices/sockets","Clamp offsets to [0, fileSize] before opening","Monitor storage health (SMART, mount errors) to catch EIO early"],"tags":["file-io","seek","go"],"backgroundTag":"seek-failed","analyzedSha":"5079fb58f1e8e62113f90c945ad71586c797d770","analyzedAt":"2026-09-03T18:10:26.153Z","contentChangedAt":"2026-09-03T18:10:26.153Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}