From 9b33cfc457cff3b51252e150f6e17d0f58d6a01e Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Mon, 20 Mar 2017 14:17:06 +0100 Subject: [PATCH] Fix/unify context-based remote storage timeouts --- storage/remote/client.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/storage/remote/client.go b/storage/remote/client.go index c3e4a3354..ee9241d2b 100644 --- a/storage/remote/client.go +++ b/storage/remote/client.go @@ -101,7 +101,9 @@ func (c *Client) Store(samples model.Samples) error { } httpReq.Header.Add("Content-Encoding", "snappy") - ctx, _ := context.WithTimeout(context.Background(), c.timeout) + ctx, cancel := context.WithTimeout(context.Background(), c.timeout) + defer cancel() + httpResp, err := ctxhttp.Do(ctx, c.client, httpReq) if err != nil { return err @@ -144,6 +146,10 @@ func (c *Client) Read(ctx context.Context, from, through model.Time, matchers me if err != nil { return nil, fmt.Errorf("unable to create request: %v", err) } + + ctx, cancel := context.WithTimeout(ctx, c.timeout) + defer cancel() + httpResp, err := ctxhttp.Do(ctx, c.client, httpReq) if err != nil { return nil, fmt.Errorf("error sending request: %v", err)