{"record":{"id":"67822d3741d11e0a","repo":"cloudflare/cloudflared","slug":"timed-out-waiting-for-lock-file-s","errorCode":null,"errorMessage":"timed out waiting for lock file %s","messagePattern":"timed out waiting for lock file (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"token/token.go","lineNumber":129,"sourceCode":"// acquireLockFile loops until it successfully creates a lock file for the\n// given token file path. The lock file is created at tokenPath + \".lock\".\n//\n// On each iteration:\n//  1. Try to create the file atomically with O_CREATE|O_EXCL.\n//     If that succeeds, write our PID + start time and return the lock.\n//  2. If the file already exists, read it and check whether the owning\n//     process is still alive (PID exists and start time matches).\n//  3. If the owner is alive, sleep for lockRetryInterval and retry.\n//  4. If the owner is dead (stale lock), remove the file and immediately\n//     retry the O_EXCL create. No sleep (the atomic create is the\n//     tiebreaker if multiple processes race to reclaim).\nfunc acquireLockFile(tokenPath string, log *zerolog.Logger) (*lockFile, error) {\n\tlockPath := tokenPath + \".lock\"\n\tdeadline := time.Now().Add(lockTimeout)\n\tlastURL := \"\"\n\tfor {\n\t\tif time.Now().After(deadline) {\n\t\t\treturn nil, fmt.Errorf(\"timed out waiting for lock file %s\", lockPath)\n\t\t}\n\t\tcontent, err := createLockFile(lockPath)\n\t\tif err == nil {\n\t\t\tlog.Debug().Str(\"path\", lockPath).Msg(\"lock file acquired\")\n\t\t\treturn &lockFile{path: lockPath, content: content, log: log}, nil\n\t\t}\n\t\tif !os.IsExist(err) {\n\t\t\treturn nil, errors.Wrapf(err, \"failed to create lock file %s\", lockPath)\n\t\t}\n\n\t\t// lock file exists, so check if the owner is still alive\n\t\tstale, content, checkErr := isLockFileStale(lockPath)\n\t\tif checkErr != nil {\n\t\t\t// file may be mid-write by another racer, or was removed\n\t\t\t// between our O_EXCL attempt and this read\n\t\t\tlog.Debug().Err(checkErr).Str(\"path\", lockPath).\n\t\t\t\tMsg(\"could not read lock file, retrying\")\n\t\t\ttime.Sleep(lockRetryInterval)","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/token/token.go#L111-L147","documentation":"Lock-contention failure in acquireLockFile: another cloudflared process holds the token lock file (tokenPath + '.lock') with a live PID and matching start time, and the loop never acquired the lock before its deadline expired. Prevents two processes from mutating the same access-token file concurrently.","triggerScenarios":"Thrown at token/token.go:129 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check for another running cloudflared process using the same token file and stop it if stale intent.","If the lock owner is truly gone but misreported, remove the stale .lock file manually.","Rerun the command once the holder exits; acquisition retries automatically until the timeout."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}