Skip to content

Commit

Permalink
agent dont report error if terminated gracefully (woodpecker-ci#3894)
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 committed Sep 5, 2024
1 parent 4289fb0 commit 0c33ca2
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions agent/rpc/client_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package rpc
import (
"context"
"encoding/json"
"fmt"
"strings"
"time"

Expand Down Expand Up @@ -85,30 +86,35 @@ 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,
codes.DeadlineExceeded,
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
}
}

Expand Down

0 comments on commit 0c33ca2

Please sign in to comment.