diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f44817f77..669b6393bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ * [BUGFIX] Compactor: Cleaner would delete bucket index when there is no block in bucket store. #6577 * [BUGFIX] Querier: Fix marshal native histogram with empty bucket when protobuf codec is enabled. #6595 * [BUGFIX] Query Frontend: Fix samples scanned and peak samples query stats when query hits results cache. #6591 +* [BUGFIX] Query Frontend: Fix panic caused by nil pointer dereference. #6609 ## 1.19.0 in progress diff --git a/pkg/frontend/v2/frontend_scheduler_worker.go b/pkg/frontend/v2/frontend_scheduler_worker.go index 61a4d33404..033da68abd 100644 --- a/pkg/frontend/v2/frontend_scheduler_worker.go +++ b/pkg/frontend/v2/frontend_scheduler_worker.go @@ -291,7 +291,7 @@ func (w *frontendSchedulerWorker) schedulerLoop(loop schedulerpb.SchedulerForFro req.response <- &frontendv2pb.QueryResultRequest{ HttpResponse: &httpgrpc.HTTPResponse{ Code: http.StatusInternalServerError, - Body: []byte(err.Error()), + Body: []byte(resp.GetError()), }, } diff --git a/pkg/frontend/v2/frontend_test.go b/pkg/frontend/v2/frontend_test.go index 6b20926e89..676070ca0f 100644 --- a/pkg/frontend/v2/frontend_test.go +++ b/pkg/frontend/v2/frontend_test.go @@ -3,6 +3,7 @@ package v2 import ( "context" "net" + "net/http" "strconv" "strings" "sync" @@ -182,6 +183,18 @@ func TestFrontendEnqueueFailure(t *testing.T) { require.True(t, strings.Contains(err.Error(), "failed to enqueue request")) } +func TestFrontendEnqueueInternalError(t *testing.T) { + errorMsg := "Some error" + f, _ := setupFrontend(t, func(f *Frontend, msg *schedulerpb.FrontendToScheduler) *schedulerpb.SchedulerToFrontend { + return &schedulerpb.SchedulerToFrontend{Status: schedulerpb.ERROR, Error: errorMsg} + }, 0) + + resp, err := f.RoundTripGRPC(user.InjectOrgID(context.Background(), "test"), &httpgrpc.HTTPRequest{}) + require.NoError(t, err) + require.Equal(t, []byte(errorMsg), resp.Body) + require.Equal(t, int32(http.StatusInternalServerError), resp.Code) +} + func TestFrontendCancellation(t *testing.T) { f, ms := setupFrontend(t, nil, 0)