{"record":{"id":"8a8ce93aadef7da9","repo":"kubernetes/kops","slug":"error-reading-file-q-v-8a8ce9","errorCode":null,"errorMessage":"error reading file %q: %v","messagePattern":"error reading file %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/dns/hosts/hosts.go","lineNumber":121,"sourceCode":"\t}\n\n\tm.records = newRecords\n}\n\n// UpdateHostsFileWithRecords updates /etc/hosts by applying the given mutation function.\nfunc UpdateHostsFileWithRecords(p string, mutator func(guarded []string) (*HostMap, error)) error {\n\t// For safety / sanity, we avoid concurrent updates from one process\n\thostsFileMutex.Lock()\n\tdefer hostsFileMutex.Unlock()\n\n\tstat, err := os.Stat(p)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error getting file status of %q: %v\", p, err)\n\t}\n\n\tdata, err := os.ReadFile(p)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error reading file %q: %v\", p, err)\n\t}\n\n\tvar guarded []string\n\tvar out []string\n\tinGuardBlock := false\n\tfor _, line := range strings.Split(string(data), \"\\n\") {\n\t\tk := strings.TrimSpace(line)\n\t\tif k == GUARD_BEGIN {\n\t\t\tif inGuardBlock {\n\t\t\t\tklog.Warningf(\"/etc/hosts guard-block begin seen while in guard block; will ignore\")\n\t\t\t}\n\t\t\tinGuardBlock = true\n\t\t}\n\n\t\tif inGuardBlock {\n\t\t\tguarded = append(guarded, line)\n\t\t} else {\n\t\t\tout = append(out, line)","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/dns/hosts/hosts.go#L103-L139","documentation":"Reading the hosts file contents failed even though stat succeeded; concurrent removal/replacement, permission changes, or I/O errors on the bind-mounted /etc/hosts.","triggerScenarios":"Thrown at pkg/dns/hosts/hosts.go:121 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry — the file may have been transiently replaced by another writer","Check the health of the /etc/hosts bind mount (it may be revoked or read-only)","Ensure the process retains read access"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}