From f337ed9663c32dbda53484d37035346e49416fa9 Mon Sep 17 00:00:00 2001 From: iyear Date: Mon, 6 Jan 2025 17:15:55 +0800 Subject: [PATCH] fix(middlewares/recovery): handle runtime context done --- core/middlewares/recovery/recovery.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/middlewares/recovery/recovery.go b/core/middlewares/recovery/recovery.go index 821e92076b..6d69de354a 100644 --- a/core/middlewares/recovery/recovery.go +++ b/core/middlewares/recovery/recovery.go @@ -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") } @@ -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: }