From 3d6d308b80d160e6758210a1d3bc4a2172736c07 Mon Sep 17 00:00:00 2001 From: Max Kotliar Date: Tue, 12 May 2026 16:00:01 +0300 Subject: [PATCH] enhance comment --- app/vmagent/remotewrite/client.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/vmagent/remotewrite/client.go b/app/vmagent/remotewrite/client.go index b643a50c12..9af3160806 100644 --- a/app/vmagent/remotewrite/client.go +++ b/app/vmagent/remotewrite/client.go @@ -327,7 +327,8 @@ func (c *client) runWorker() { c.fq.MustWriteBlockIgnoreDisabledPQ(block) return case <-c.stopCh: - // c must be stopped. Wait for a while in the hope the block will be sent. + // c must be stopped. Wait up to 5 seconds for the in-flight request to complete. + // If it succeeds, drain the remaining in-memory queue before returning. stopCtx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() @@ -336,12 +337,13 @@ func (c *client) runWorker() { if !ok { // Return unsent block to the queue. c.fq.MustWriteBlockIgnoreDisabledPQ(block) + } else { + c.drainInMemoryQueue(stopCtx, block[:0]) } case <-stopCtx.Done(): // Return unsent block to the queue. c.fq.MustWriteBlockIgnoreDisabledPQ(block) } - c.drainInMemoryQueue(stopCtx, block[:0]) return } }