Skip to content

Commit

Permalink
gRPC: translate errors to context.Canceled (sourcegraph#47986)
Browse files Browse the repository at this point in the history
The search pipeline has special treatment for `context.Canceled` errors.
However, the gRPC error returned when a context canceled does _not_
respond to `errors.Is(err, context.Canceled)`. This means that our
special treatment fails, and the error gets returned, causing the test
to fail.

A real fix here will be to add interceptors to our gRPC clients that
translates these automatically.

## Test plan

Running backend integration tests that were previously failing
consistently.
  • Loading branch information
camdencheek committed Feb 21, 2023
1 parent 52ac50e commit 254c40e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion internal/gitserver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,9 @@ func (c *RemoteGitCommand) sendExec(ctx context.Context) (_ io.ReadCloser, errRe
}
r := streamio.NewReader(func() ([]byte, error) {
msg, err := stream.Recv()
if err != nil {
if status.Code(err) == codes.Canceled {
return nil, context.Canceled
} else if err != nil {
return nil, err
}
return msg.GetData(), nil
Expand Down
4 changes: 4 additions & 0 deletions internal/search/searcher/client_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/sourcegraph/sourcegraph/cmd/searcher/protocol"
"github.com/sourcegraph/sourcegraph/internal/api"
Expand Down Expand Up @@ -98,6 +100,8 @@ func SearchGRPC(
msg, err := resp.Recv()
if errors.Is(err, io.EOF) {
return false, nil
} else if status.Code(err) == codes.Canceled {
return false, context.Canceled
} else if err != nil {
return false, err
}
Expand Down

0 comments on commit 254c40e

Please sign in to comment.