Skip to content

fix: shut down query-frontend and querier gracefully - #7967

Open
electron0zero wants to merge 13 commits into
grafana:mainfrom
electron0zero:fix_incorrect_shutdown
Open

electron0zero wants to merge 13 commits into
grafana:mainfrom
electron0zero:fix_incorrect_shutdown

Conversation

@electron0zero

@electron0zero electron0zero commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

What this PR does:

deadlock stopped query-frontend and querier from calling server.Shutdown() on shutdown, so these services waited for the grace period and it was SIGKILLed

deadlocks happened because request queue waited on a cleanup ticker dskit had already stopped, and the store waited on a blocklist poller.

Also stops usage-report reporting itself as failed on a clean shutdown.

Added test and new e2e test to ensure all components have a clean shutdown and this class of bugs don't happen again.

we are not sure when we got this bug because from what I recall we have been seen dropped connections during rollouts for a while in the logs.

we reworked this queue logic in #3996 but I think this bug existed way before that and been around from early days of tempo.

Which issue(s) this PR fixes:
Relates to #7983

Checklist

  • Tests updated
  • Documentation added
  • Changelog entry added under .chloggen/ (run make chlog-new, or make chlog-new FILENAME=<name> to override the default branch-name file; see .chloggen/README.md)

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread modules/frontend/queue/queue.go Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5ced048. Configure here.

Comment thread integration/operations/graceful_shutdown_test.go Outdated
dskit stops the cleanup ticker before calling stopping(), so the wait for an empty queue map could never be satisfied and SIGTERM hung until SIGKILL.
query-frontend and querier enable polling with context.Background(), so Reader.Shutdown() waited forever for a poll loop that never exits.
Without a cluster seed, running() returned context.Canceled on SIGTERM, so dskit marked usage-report failed on every clean shutdown.
A service that never terminates used to hang the process with nothing in the logs. This named the second deadlock on its first run.
Stop() returns nil once a service exits cleanly, which the shutdown fixes now make the normal case, so the unguarded deref would panic.
Guards the bug class rather than the two instances found: fails if any component is SIGKILLed on SIGTERM. Validated against the pre-fix binary.
The rebase onto the v3 module migration (grafana#7971) replayed these files without rewriting their imports, breaking lint and vendor check under -mod=vendor.
Refuse new work once shutdown starts so the drain converges, fail anything it could not dispatch, and answer a stopped queue with 503 instead of a 500.
…IGTERM

At 1% the bound held only while the frontend refused for under 20ms.
traces_created_total can increment before the trace answers a query.
The 2s lookback raced a live-store cold start. Raise it to 20s and the gap to 25s.
Unrelated to shutdown. They move to their own PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant