From 2d607a9ae493bda1a325b96a2e202a6c5841d24a Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 12 Jul 2024 18:24:55 -0700 Subject: [PATCH] agent dont report error if terminated gracefully (#3894) --- agent/rpc/client_grpc.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/agent/rpc/client_grpc.go b/agent/rpc/client_grpc.go index b49b0e98f..4c42224b4 100644 --- a/agent/rpc/client_grpc.go +++ b/agent/rpc/client_grpc.go @@ -17,6 +17,7 @@ package rpc import ( "context" "encoding/json" + "fmt" "strings" "time" @@ -85,15 +86,13 @@ func (c *client) Next(ctx context.Context, f rpc.Filter) (*rpc.Workflow, error) break } - // TODO: remove after adding continuous data exchange by something like #536 - if strings.Contains(err.Error(), "\"too_many_pings\"") { - // https://github.com/woodpecker-ci/woodpecker/issues/717#issuecomment-1049365104 - log.Trace().Err(err).Msg("grpc: to many keepalive pings without sending data") - } else { - log.Error().Err(err).Msgf("grpc error: done(): code: %v", status.Code(err)) - } - switch status.Code(err) { + case codes.Canceled: + if ctx.Err() != nil { + // expected as context was canceled + return nil, nil + } + return nil, err case codes.Aborted, codes.DataLoss, @@ -101,14 +100,21 @@ func (c *client) Next(ctx context.Context, f rpc.Filter) (*rpc.Workflow, error) codes.Internal, codes.Unavailable: // non-fatal errors + // TODO: remove after adding continuous data exchange by something like #536 + if strings.Contains(err.Error(), "\"too_many_pings\"") { + // https://github.com/woodpecker-ci/woodpecker/issues/717#issuecomment-1049365104 + log.Trace().Err(err).Msg("grpc: to many keepalive pings without sending data") + } else { + log.Error().Err(err).Msgf("grpc error: next(): code: %v", status.Code(err)) + } default: - return nil, err + return nil, fmt.Errorf("grpc error: next(): code: %v: %w", status.Code(err), err) } select { case <-time.After(retry.NextBackOff()): case <-ctx.Done(): - return nil, ctx.Err() + return nil, nil } }