mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-08-30 20:35:27 +00:00
fix(agent): handle context cancellation (#5323)
Signed-off-by: ivaltryek <meet.vasani86@gmail.com> Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
This commit is contained in:
parent
f209256bd9
commit
5c9fc61619
@ -267,6 +267,11 @@ func run(ctx context.Context, c *cli.Command, backends []types.Backend) error {
|
||||
err := client.ReportHealth(grpcCtx)
|
||||
if err != nil {
|
||||
log.Err(err).Msg("failed to report health")
|
||||
// Check if the error is due to context cancellation
|
||||
if grpcCtx.Err() != nil || agentCtx.Err() != nil {
|
||||
log.Debug().Msg("terminating health reporting due to context cancellation")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
select {
|
||||
@ -291,8 +296,18 @@ func run(ctx context.Context, c *cli.Command, backends []types.Backend) error {
|
||||
|
||||
log.Debug().Msg("polling new steps")
|
||||
if err := runner.Run(agentCtx, shutdownCtx); err != nil {
|
||||
log.Error().Err(err).Msg("runner done with error")
|
||||
return err
|
||||
log.Error().Err(err).Msg("runner error, retrying...")
|
||||
// Check if context is canceled
|
||||
if agentCtx.Err() != nil {
|
||||
return nil
|
||||
}
|
||||
// Wait a bit before retrying to avoid hammering the server
|
||||
select {
|
||||
case <-agentCtx.Done():
|
||||
return nil
|
||||
case <-time.After(time.Second * 5):
|
||||
// Continue to next iteration
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user