Skip to content

Commit

Permalink
change the return code when shutting down from Canceled to Unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
sduchesneau committed Dec 5, 2023
1 parent 5c76077 commit 295a633
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions service/tier1.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"sync"

"github.com/streamingfast/bstream"
"github.com/streamingfast/dgrpc"

"github.com/streamingfast/bstream/hub"
"github.com/streamingfast/bstream/stream"
bsstream "github.com/streamingfast/bstream/stream"
"github.com/streamingfast/dauth"
"github.com/streamingfast/dgrpc"
"github.com/streamingfast/dmetering"
"github.com/streamingfast/dstore"
"github.com/streamingfast/logging"
Expand Down Expand Up @@ -48,6 +48,8 @@ import (
"google.golang.org/protobuf/proto"
)

var errShuttingDown = errors.New("endpoint is shutting down, please reconnect")

type Tier1Service struct {
*shutter.Shutter
ssconnect.UnimplementedStreamHandler
Expand Down Expand Up @@ -231,7 +233,7 @@ func (s *Tier1Service) Blocks(
case <-ctx.Done():
return
case <-s.Terminating():
cancelRunning(fmt.Errorf("endpoint is shutting down, please reconnect"))
cancelRunning(errShuttingDown)
}
}()

Expand Down Expand Up @@ -550,6 +552,9 @@ func toGRPCError(ctx context.Context, err error) error {
if errors.Is(err, context.Canceled) {
if context.Cause(ctx) != nil {
err = context.Cause(ctx)
if err == errShuttingDown {
return connect.NewError(connect.CodeUnavailable, err)
}
}
return connect.NewError(connect.CodeCanceled, err)
}
Expand Down

0 comments on commit 295a633

Please sign in to comment.