diff --git a/executable.go b/executable.go index cf8431c87..ea25a91e5 100644 --- a/executable.go +++ b/executable.go @@ -2,12 +2,11 @@ package hedera import ( "context" - "github.com/pkg/errors" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" "math" "time" + "github.com/pkg/errors" + "github.com/hashgraph/hedera-sdk-go/v2/proto" "google.golang.org/grpc" ) @@ -114,7 +113,7 @@ func execute( if err != nil { errPersistent = err - if grpcErr, ok := status.FromError(err); ok && (grpcErr.Code() == codes.Unavailable || grpcErr.Code() == codes.ResourceExhausted) { + if defaultRetryHandler(err) { node.increaseDelay() continue } diff --git a/topic_message_query.go b/topic_message_query.go index 3f5ed4992..e0cac09e7 100644 --- a/topic_message_query.go +++ b/topic_message_query.go @@ -4,6 +4,7 @@ import ( "context" "io" "math" + "regexp" "time" "github.com/hashgraph/hedera-sdk-go/v2/proto/mirror" @@ -11,6 +12,8 @@ import ( "google.golang.org/grpc/status" ) +var RST_STREAM *regexp.Regexp + type TopicMessageQuery struct { pb *mirror.ConsensusTopicQuery errorHandler func(stat status.Status) @@ -219,8 +222,24 @@ func defaultRetryHandler(err error) bool { code := status.Code(err) switch code { - case codes.NotFound, codes.ResourceExhausted, codes.Internal, codes.Unavailable: + case codes.NotFound, codes.ResourceExhausted, codes.Unavailable: return true + case codes.Internal: + if RST_STREAM == nil { + var err1 error + RST_STREAM, err1 = regexp.Compile(".*(rst.stream.*internal.error|internal.error.*rst.stream).*") + if err1 != nil { + panic(err1) + } + } + + grpcErr, ok := status.FromError(err) + + if !ok { + return false + } + + return RST_STREAM.FindIndex([]byte(grpcErr.Message())) != nil default: return false }