Stop holding the write lock across proxy shutdown drain - #324
Open
damilolaedwards wants to merge 1 commit into
Open
Stop holding the write lock across proxy shutdown drain#324damilolaedwards wants to merge 1 commit into
damilolaedwards wants to merge 1 commit into
Conversation
Stop held the server's write lock for its entire duration, including the call to httpSrv.Shutdown, which blocks until in-flight requests finish. The /ready handler took the same lock to read the readiness flag, so a /ready request landing while Stop held the lock would park on it, keeping its connection open. Shutdown then waited on that same connection to go idle, which could never happen while the handler waited on a lock only Stop's own completion would release. A rolling restart with active readiness probing could deadlock for the entire shutdown budget. Make the readiness flag an atomic so /ready and Ready() never contend for the lock at all, and restructure Stop to hold the lock only for the bounded teardown steps, releasing it before the blocking shutdown and drain wait. Stop is also now idempotent via an atomic compare-and- swap instead of a started check under the lock.
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
Stop held the server's write lock for its entire duration, including the
call to httpSrv.Shutdown, which blocks until in-flight requests finish. The
/ready handler took the same lock to read the readiness flag, so a /ready
request landing while Stop held the lock would park on it, keeping its
connection open. Shutdown then waited on that same connection to go idle,
which could never happen while the handler waited on a lock only Stop's own
completion would release. A rolling restart with active readiness probing
could deadlock for the entire shutdown budget.
Makes the readiness flag an atomic so /ready and Ready() never contend for
the lock at all, and restructures Stop to hold the lock only for the
bounded teardown steps, releasing it before the blocking shutdown and drain
wait. Stop is also now idempotent via an atomic compare-and-swap instead of
a started check under the lock.
Test plan
go test -race ./pkg/proxy/...and confirm Stop returns promptly, and confirm Stop is safe under
concurrent callers; confirmed the traffic test fails (full timeout,
deadline exceeded) on the old code
go build ./...,go vet ./...