{"record":{"id":"6231c7d2f9656a16","repo":"kubernetes/kubernetes","slug":"unable-to-acquire-file-lock-on-q-w","errorCode":null,"errorMessage":"unable to acquire file lock on %q: %w","messagePattern":"unable to acquire file lock on %q: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"cmd/kubelet/app/server.go","lineNumber":702,"sourceCode":"\t\t\tkernelVersion, err := utilkernel.GetVersion()\n\t\t\tif err != nil {\n\t\t\t\tlogger.Error(err, \"Failed to detect kernel version for MemoryQoS compatibility check\")\n\t\t\t} else if kernelVersion.LessThan(utilversion.MustParseGeneric(utilkernel.MemoryQoSMinKernelVersion)) {\n\t\t\t\tlogger.Info(\"Warning: MemoryQoS memory.high throttling may cause process livelock on older kernels\",\n\t\t\t\t\t\"currentKernel\", kernelVersion,\n\t\t\t\t\t\"minimumKernel\", utilkernel.MemoryQoSMinKernelVersion)\n\t\t\t}\n\t\t}\n\t}\n\t// Obtain Kubelet Lock File\n\tif s.ExitOnLockContention && s.LockFilePath == \"\" {\n\t\treturn errors.New(\"cannot exit on lock file contention: no lock file specified\")\n\t}\n\tdone := make(chan struct{})\n\tif s.LockFilePath != \"\" {\n\t\tlogger.Info(\"Acquiring file lock\", \"path\", s.LockFilePath)\n\t\tif err := flock.Acquire(s.LockFilePath); err != nil {\n\t\t\treturn fmt.Errorf(\"unable to acquire file lock on %q: %w\", s.LockFilePath, err)\n\t\t}\n\t\tif s.ExitOnLockContention {\n\t\t\tlogger.Info(\"Watching for inotify events\", \"path\", s.LockFilePath)\n\t\t\tif err := watchForLockfileContention(ctx, s.LockFilePath, done); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\t}\n\n\tif len(s.ShowHiddenMetricsForVersion) > 0 {\n\t\tmetrics.SetShowHidden()\n\t}\n\n\t// About to get clients and such, detect standaloneMode\n\tstandaloneMode := true\n\tif len(s.KubeConfig) > 0 {\n\t\tstandaloneMode = false\n\t}","sourceCodeStart":684,"sourceCodeEnd":720,"githubUrl":"https://github.com/kubernetes/kubernetes/blob/b882c60b4023bdf09264c2d5d30a2cadebc240fb/cmd/kubelet/app/server.go#L684-L720","documentation":"From run() (server.go:701-702): flock.Acquire failed on --lock-file-path. The lock file enforces that only one kubelet runs per node (and supports --exit-on-lock-contention for self-termination on contention). Acquisition fails when the file cannot be created/opened or an existing holder won't release within the retry window.","triggerScenarios":"Another kubelet process is already running and holds the lock; the lock-file path's directory does not exist or is not writable; permission denied on the path; or the filesystem does not support flock semantics.","commonSituations":"A second kubelet was started (double-launch); a previous kubelet crashed without releasing the lock and the stale lock is still held (rare with flock, which releases on process exit); --lock-file-path points at a read-only mount.","solutions":["Check for a running kubelet: `pgrep -a kubelet` and `systemctl status kubelet` — stop duplicates.","Confirm the lock-file directory exists and is writable by the kubelet user.","If the prior process is truly dead but the lock lingers, remove the lock file and restart.","On shared/read-only filesystems, move --lock-file-path to a local writable dir (e.g. /var/run)."],"exampleFix":"# before (read-only mount)\n--lock-file-path=/etc/kubernetes/kubelet.lock\n# after (local writable)\n--lock-file-path=/var/run/kubelet.lock","handlingStrategy":"validation","validationCode":"// Preflight: confirm no other kubelet holds the lock and the dir is writable.\nif running, _ := pgrepKubelet(); running {\n    return errors.New(\"kubelet already running; refusing to start a second instance\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Place --lock-file-path on a local writable filesystem (e.g. /var/run), never a read-only mount.","Use systemd as the single launcher to avoid double-starting kubelet."],"tags":["kubelet","lock-file","contention","filesystem","startup"],"analyzedSha":"b882c60b4023bdf09264c2d5d30a2cadebc240fb","analyzedAt":"2026-08-07T04:07:48.144Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}