scrape: timeout WriteRaw, drop sp.mtx before waiting on loops#6361
Merged
Conversation
The per-target scrape loop bounded only the HTTP scrape with scrape_timeout; the subsequent store.WriteRaw call ran under the bare scrapeCtx with no deadline. When write latency spiked, each iteration blocked indefinitely inside WriteRaw and the target appeared to stop scraping (time.Ticker doesn't accumulate, so only one make-up scrape fires after the call returns). WriteRaw now runs under context.WithTimeout(scrapeCtx, scrape_timeout) so a slow store fails the scrape and the next interval fires on time. scrapePool.stop() and reload() also held sp.mtx across wg.Wait() for old loops to terminate. A loop wedged inside WriteRaw would therefore block sp.mtx, and — via Manager.ApplyConfig / Stop holding m.mtxScrape — block the manager's Run loop from draining new target sets, freezing every pool. Both methods now snapshot the loops under sp.mtx, release the lock, and wait on goroutines outside it, matching the pattern already used by sync().
|
✅ Meticulous spotted 0 visual differences across 288 screens tested: view results. Meticulous evaluated ~4 hours of user flows against your PR. Expected differences? Click here. Last updated for commit |
asubiotto
approved these changes
May 19, 2026
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.
The per-target scrape loop bounded only the HTTP scrape with scrape_timeout; the subsequent store.WriteRaw call ran under the bare scrapeCtx with no deadline. When write latency spiked, each iteration blocked indefinitely inside WriteRaw and the target appeared to stop scraping (time.Ticker doesn't accumulate, so only one make-up scrape fires after the call returns). WriteRaw now runs under context.WithTimeout(scrapeCtx, scrape_timeout) so a slow store fails the scrape and the next interval fires on time.
scrapePool.stop() and reload() also held sp.mtx across wg.Wait() for old loops to terminate. A loop wedged inside WriteRaw would therefore block sp.mtx, and — via Manager.ApplyConfig / Stop holding m.mtxScrape — block the manager's Run loop from draining new target sets, freezing every pool. Both methods now snapshot the loops under sp.mtx, release the lock, and wait on goroutines outside it, matching the pattern already used by sync().