From 295a6334fb5e32e1fb2bb541dda80ce2f6c2ea60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Duchesneau?= Date: Tue, 5 Dec 2023 15:42:19 -0500 Subject: [PATCH] change the return code when shutting down from Canceled to Unavailable --- service/tier1.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/service/tier1.go b/service/tier1.go index a24dbafdc..05fa29b7b 100644 --- a/service/tier1.go +++ b/service/tier1.go @@ -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" @@ -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 @@ -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) } }() @@ -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) }