Skip to content

Commit

Permalink
Fix panic caused by nil pointer dereference
Browse files Browse the repository at this point in the history
  • Loading branch information
rapphil committed Feb 25, 2025
1 parent fc6c40d commit 81ae649
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/frontend/v2/frontend_scheduler_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
},
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/frontend/v2/frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v2
import (
"context"
"net"
"net/http"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 81ae649

Please sign in to comment.