{"record":{"id":"f754ccb77e33b714","repo":"VictoriaMetrics/VictoriaMetrics","slug":"cannot-read-q-w-f754cc","errorCode":null,"errorMessage":"cannot read %q: %w","messagePattern":"cannot read %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/persistentqueue/persistentqueue.go","lineNumber":662,"sourceCode":"}\n\nfunc (mi *metainfo) WriteToFile(path string) error {\n\tdata, err := json.Marshal(mi)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot marshal persistent queue metainfo %#v: %w\", mi, err)\n\t}\n\tfs.MustWriteAtomic(path, data, true)\n\treturn nil\n}\n\nfunc (mi *metainfo) ReadFromFile(path string) error {\n\tmi.Reset()\n\tdata, err := os.ReadFile(path)\n\tif err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\treturn err\n\t\t}\n\t\treturn fmt.Errorf(\"cannot read %q: %w\", path, err)\n\t}\n\tif err := json.Unmarshal(data, mi); err != nil {\n\t\treturn fmt.Errorf(\"cannot unmarshal persistent queue metainfo from %q: %w\", path, err)\n\t}\n\tif mi.ReaderOffset > mi.WriterOffset {\n\t\treturn fmt.Errorf(\"invalid data read from %q: readerOffset=%d cannot exceed writerOffset=%d\", path, mi.ReaderOffset, mi.WriterOffset)\n\t}\n\treturn nil\n}\n","sourceCodeStart":644,"sourceCodeEnd":672,"githubUrl":"https://github.com/VictoriaMetrics/VictoriaMetrics/blob/5079fb58f1e8e62113f90c945ad71586c797d770/lib/persistentqueue/persistentqueue.go#L644-L672","documentation":"ReadFromFile loads persistent queue metainfo (reader/writer offsets) from a JSON file at the given path. This error wraps a non-ENOENT filesystem error returned by os.ReadFile, meaning the file exists but could not be read (permissions, I/O error, path is a directory, etc.). os.IsNotExist errors are returned unwrapped as sentinel behavior; everything else is wrapped here.","triggerScenarios":"Calling ReadFromFile(path) (directly or via tryOpeningQueue when opening a FastQueue) where the metainfo file exists but os.ReadFile fails with an error other than fs.ErrNotExist — e.g. EACCES, EISDIR, EIO, device errors.","commonSituations":"Queue data directory copied with wrong ownership/permissions; metainfo path points at a directory instead of a file; disk or network-mounted storage (NFS) failure; file deleted between existence check and read by another process; running the app as a different user after switching service accounts.","solutions":["Check filesystem permissions on the metainfo file and its directory (ls -l) and ensure the process user can read them","Verify the path points to a regular file, not a directory (file <path>)","Inspect the wrapped OS error (%w) with errors.As(*fs.PathError) to identify errno and address the underlying cause","Check disk health / mount state (dmesg, df) if EIO is reported","If the metainfo file is corrupt or unrecoverable, restore it from backup or recreate the queue directory (data loss may apply)"],"exampleFix":"// before: app runs as user 'app', queue dir owned by root\n// after:\nsudo chown -R app:app /var/lib/vm/queue\nchmod 700 /var/lib/vm/queue","handlingStrategy":"try-catch","validationCode":"if fi, err := os.Stat(path); err != nil {\n    return fmt.Errorf(\"metainfo inaccessible: %w\", err)\n} else if !fi.Mode().IsRegular() {\n    return fmt.Errorf(\"%s is not a regular file\", path)\n} else if file, err := os.Open(path); err != nil {\n    return fmt.Errorf(\"metainfo not readable: %w\", err)\n} else { file.Close() }","typeGuard":"func isReadableFile(path string) bool {\n    fi, err := os.Stat(path)\n    return err == nil && fi.Mode().IsRegular()\n}","tryCatchPattern":"if err := pq.ReadFromFile(path); err != nil {\n    if os.IsNotExist(err) {\n        // first run: initialize fresh metainfo\n    } else {\n        var pe *fs.PathError\n        if errors.As(err, &pe) {\n            log.Printf(\"metainfo read failed: op=%s path=%s err=%v\", pe.Op, pe.Path, pe.Err)\n        }\n        return err\n    }\n}","preventionTips":["Run the service under a user with read access to the queue data directory","Provision consistent ownership/permissions in deployment (chown/chmod in entrypoint)","Never point the queue path at a directory or mount point itself","Monitor disk/mount health for storage that can return EIO"],"tags":["filesystem","io","go"],"backgroundTag":"file-read-permission-denied","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"}