Skip to content

feat: graceful shutdown on SIGINT/SIGTERM#206

Open
prochac wants to merge 1 commit into
lablabs:masterfrom
prochac:feat/graceful-shutdown
Open

feat: graceful shutdown on SIGINT/SIGTERM#206
prochac wants to merge 1 commit into
lablabs:masterfrom
prochac:feat/graceful-shutdown

Conversation

@prochac

@prochac prochac commented Jun 15, 2026

Copy link
Copy Markdown

Propagate context through the fetch layer to cancel in-flight requests on shutdown, and drain the HTTP server before exit.

Pull Request Template

Description

Adds graceful shutdown on SIGINT/SIGTERM. The exporter derives a context from
signal.NotifyContext; on signal it shuts down the HTTP server with a bounded
drain and cancels in-flight Cloudflare requests instead of being killed mid-flight.

Also:

  • run the scrape loop synchronously, so ticks coalesce instead of piling up
    overlapping scrapes (also fixes a per-iteration time.NewTicker leak in the
    old loop)
  • suppress expected context.Canceled errors in fetch logs so shutdown is quiet

Type of Change

  • New feature (non-breaking change which adds functionality)

Testing

  • I have run make pr-tests and all tests pass
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

fmt-check, lint (golangci-lint: 0 issues), and build pass. The test
step (run_e2e.sh) couldn't run in my environment — it requires the venom
binary and a .env file, neither available here. Verified manually instead:
sent SIGTERM and confirmed clean drain (Shutdown complete, exit 0); with an
in-flight request (routed through a hanging proxy) confirmed the
context.Canceled error is suppressed (0 error log lines).

Code Quality

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation

Additional Notes

No documentation/config changes needed — cf_timeout and existing flags are
unchanged. Shutdown drain is bounded at 10s; in-flight scrapes are best-effort
and abandoned on exit (their results are discarded anyway).

Propagate context through the fetch layer to cancel in-flight requests
on shutdown, and drain the HTTP server before exit.

fixed:
- run the scrape loop synchronously so ticks coalesce instead of piling
  up overlapping scrapes
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