{"record":{"id":"a259696e4d540bc9","repo":"vitessio/vitess","slug":"can-t-access-file-myidfile-staterr-error","errorCode":null,"errorMessage":"can't access file ${myidFile}: ${statErr.Error()}","messagePattern":"can't access file (.+?): (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/zkctl/zkctl.go","lineNumber":254,"sourceCode":"\t}\n\tvar removalErr error\n\tfor _, dir := range zkd.config.DirectoryList() {\n\t\tif err := os.RemoveAll(dir); err != nil {\n\t\t\tlog.Error(fmt.Sprintf(\"failed removing %v: %v\", dir, err.Error()))\n\t\t\tremovalErr = err\n\t\t}\n\t}\n\treturn removalErr\n}\n\n// Inited returns true if the server config has been initialized.\nfunc (zkd *Zkd) Inited() bool {\n\tmyidFile := zkd.config.MyidFile()\n\t_, statErr := os.Stat(myidFile)\n\tif statErr == nil {\n\t\treturn true\n\t} else if statErr.(*os.PathError).Err != syscall.ENOENT {\n\t\tpanic(\"can't access file \" + myidFile + \": \" + statErr.Error())\n\t}\n\treturn false\n}\n","sourceCodeStart":236,"sourceCodeEnd":258,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/zkctl/zkctl.go#L236-L258","documentation":"Zkd.Inited() checks for the existence of the zookeeper myid file to determine if zookeeper has been initialized. It stats the myid file; if stat fails with anything other than ENOENT (file-not-found), it panics because it cannot safely determine initialization state. This is a defensive panic for unexpected filesystem errors like permission denial.","triggerScenarios":"Calling zkd.Inited() (directly or via zkd.Init()) when os.Stat on the myid file path (zkd.config.MyidFile()) fails with an error other than syscall.ENOENT — e.g. EACCES on a directory the process cannot read, ELOOP on a symlink cycle, or the path being on a broken/unavailable mount.","commonSituations":"Zookeeper data directory owned by a different user than the vtctld/vtcombo process; myid file path pointing through a symlink loop; NFS mount down when zookeeper runs remotely; misconfigured ZK config dir after a container image change.","solutions":["Fix permissions on the directory containing the myid file so the process user can stat it (chown/chmod).","Check that the myid file path in the zk config is valid and not a broken symlink (ls -la the path).","Verify the filesystem hosting the zookeeper data dir is mounted and healthy (df / mount output).","If the panic is undesirable, patch Inited() to return false with a logged error instead of panicking on non-ENOENT stat errors."],"exampleFix":"// before\n} else if statErr.(*os.PathError).Err != syscall.ENOENT {\n\tpanic(\"can't access file \" + myidFile + \": \" + statErr.Error())\n}\n// after\n} else if statErr.(*os.PathError).Err != syscall.ENOENT {\n\tlog.Warningf(\"can't access file %s: %v; treating as not inited\", myidFile, statErr)\n\treturn false\n}","handlingStrategy":"validation","validationCode":"myidFile := zkd.config.MyidFile()\nif _, err := os.Stat(myidFile); err != nil {\n\tif pe, ok := err.(*os.PathError); ok && pe.Err == syscall.ENOENT {\n\t\t// not inited, safe to proceed with Init\n\t} else {\n\t\t// fix permissions/mount before calling Inited/Init\n\t\tlog.Warningf(\"myid file inaccessible: %v\", err)\n\t}\n}","typeGuard":"func isENOENT(err error) bool {\n\tvar pe *os.PathError\n\treturn errors.As(err, &pe) && errors.Is(pe.Err, syscall.ENOENT)\n}","tryCatchPattern":null,"preventionTips":["Ensure the zookeeper data directory is owned and readable by the vitess process user before startup.","Verify TMPDIR/data-dir mounts are healthy in containers and check for symlink loops in configured paths.","Prefer errors.As/errors.Is over blind type assertions when handling os.Stat errors in your own code."],"tags":["filesystem","zookeeper","panic","permissions"],"backgroundTag":"file-access-denied","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}