Skip to content

Commit

Permalink
fix(middlewares/recovery): handle runtime context done
Browse files Browse the repository at this point in the history
  • Loading branch information
iyear committed Jan 6, 2025
1 parent d2c76ed commit f337ed9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions core/middlewares/recovery/recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (r *recovery) Handle(next tg.Invoker) telegram.InvokeFunc {

return backoff.RetryNotify(func() error {
if err := next.Invoke(ctx, input, output); err != nil {
if r.shouldRecover(err) {
if r.shouldRecover(ctx, err) {
return errors.Wrap(err, "recover")
}

Expand All @@ -47,11 +47,13 @@ func (r *recovery) Handle(next tg.Invoker) telegram.InvokeFunc {
}
}

func (r *recovery) shouldRecover(err error) bool {
func (r *recovery) shouldRecover(ctx context.Context, err error) bool {
// context in recovery is used to stop recovery process by external os signal, otherwise we will wait till max retries when user press ctrl+c
select {
case <-r.ctx.Done():
return false
case <-ctx.Done():
return false
default:
}

Expand Down

0 comments on commit f337ed9

Please sign in to comment.