From 742196b6c4918d9d08b8349182b12471d9b223e1 Mon Sep 17 00:00:00 2001 From: Erlan Zholdubai uulu Date: Tue, 19 Mar 2024 10:37:43 -0700 Subject: [PATCH] add context cancellation check at get series result iteration (#13766) * add context cancellation check at get series iteration * add warnings and closer on error * add test --------- Signed-off-by: Erlan Zholdubai uulu --- web/api/v1/api.go | 3 +++ web/api/v1/api_test.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/web/api/v1/api.go b/web/api/v1/api.go index b56026e45e..dc22365073 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -882,6 +882,9 @@ func (api *API) series(r *http.Request) (result apiFuncResult) { warnings := set.Warnings() for set.Next() { + if err := ctx.Err(); err != nil { + return apiFuncResult{nil, returnAPIError(err), warnings, closer} + } metrics = append(metrics, set.At().Labels()) if len(metrics) >= limit { diff --git a/web/api/v1/api_test.go b/web/api/v1/api_test.go index 63a0225357..4158e544ef 100644 --- a/web/api/v1/api_test.go +++ b/web/api/v1/api_test.go @@ -3568,6 +3568,9 @@ func TestReturnAPIError(t *testing.T) { }, { err: errors.New("exec error"), expected: errorExec, + }, { + err: context.Canceled, + expected: errorCanceled, }, }