Repository navigation
Conversation
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.
Problem
After SIGTERM,
Supervisor.Runcontinues selecting on the closedgracefulShutdownCchannel. Since receives from a closed channel are always ready, the supervisor loop spins throughout the graceful shutdown period and consumes about one CPU core.Change
Disable the supervisor's graceful-shutdown select case after its first notification.
Outcome
Observed during a local test with a long-lived SSE request:
The SSE request completed after SIGTERM, and cloudflared exited after draining.
Reproduction
Run a local origin that streams one SSE event per second for 90 seconds:
Start cloudflared with a Quick Tunnel and its metrics/pprof listener:
Open the generated
trycloudflare.comURL in another terminal, keeping the stream open:Send SIGTERM to the cloudflared process while the stream is active:
Observe CPU during the drain with
topor by sampling the process CPU time. Before the fix, cloudflared used about one core until shutdown completed; after the fix, it stayed near idle.Inspect goroutine state during the drain:
curl 'http://127.0.0.1:20241/debug/pprof/goroutine?debug=2'Before the fix, the supervisor goroutine was runnable in
Supervisor.Run. After the fix, it was blocked in the mainselectwhile waiting for shutdown work to finish.Closes #1753
I acknowledge PR #1755 covers the same fix and I'm comfortable with it.