fix: release the app token lock when the fetch completes - #1713
Open
stareezy-1 wants to merge 2 commits into
Open
fix: release the app token lock when the fetch completes#1713stareezy-1 wants to merge 2 commits into
stareezy-1 wants to merge 2 commits into
Conversation
The replace directive pins the QUIC stack to a fork based on quic-go v0.45, which predates the fix for CVE-2025-59530 (GHSA-47m2-4cr7-mhcw): a server that sends HANDSHAKE_DONE before the handshake actually finishes makes the client drop Handshake keys before Initial keys, and the next undecryptable packet trips a panic in the connection path (remote client crash). The fork pin is bumped to a commit that backports quic-go#5354 onto the exact previously-pinned fork state (verified: the only source change is the 7-line drop-initial-keys fix in connection.go).
getToken acquired the per-app lock file and held it for the whole process lifetime. When access login fetches a token, verifies it at the edge, and finds it invalid (e.g. with Enable Binding Cookie enabled), it removes the token and fetches again in the same process — acquireLockFile then found its own lock (own PID alive), printed 'Another cloudflared process (pid N)' with its own PID, and hung until lockTimeout. Release the app and org token locks when the fetch completes. The lock still serializes concurrent transfers across processes; a same-process re-fetch can now acquire it again. releaseLockFile only removes the lock if it is still owned by this process (PID and start time match), so a lock reclaimed by another process is left alone. Closes cloudflare#1692.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1692
Problem
cloudflared access logindeadlocks forever against its own token lock file whenever the token minted during login fails the edge verification step (most commonly when the Access application has Enable Binding Cookie enabled). Every retry hangs the same way, and the "Another cloudflared process (pid N) is already waiting for authentication" banner names the process's own PID.Root cause:
getTokenacquires the per-app token lock viaacquireLockFileand holds it for the whole process lifetime. The login flow (verifyTokenAtEdge) fetches a token, verifies it at the edge, finds it invalid, callsRemoveTokenIfExists, and fetches again in the same process —acquireLockFilethen finds its own lock (own PID alive, so the stale-reclaim never fires) and waits untillockTimeout, self-deadlocked.Fix
Release the app and org token locks when the fetch completes:
releaseLockFileremoves the lock file only if it is still owned by this process (PID and start time match), so a lock reclaimed by another process is left alone.getTokennowdefers the release for both the app-token and org-token locks.The lock still serializes concurrent transfers across processes; a same-process re-fetch can now acquire it again instead of deadlocking.
Tests
Two new tests in
token/lockfile_test.go:TestReleaseLockFileAllowsReacquirelockTimeout)TestReleaseLockFileDoesNotRemoveOtherProcessLockFull
tokenpackage tests pass;go vet ./token/clean.