From 9059ed0692897ee90ea9d4cdfc92724c1527c3d3 Mon Sep 17 00:00:00 2001 From: roc Date: Fri, 4 Aug 2023 15:48:37 +0800 Subject: [PATCH] execute retry hook in reverse order --- request.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/request.go b/request.go index 3c7ca623..4a40df75 100644 --- a/request.go +++ b/request.go @@ -677,8 +677,10 @@ func (r *Request) do() (resp *Response, err error) { // need retry, attempt to retry r.RetryAttempt++ - for _, hook := range r.retryOption.RetryHooks { // run retry hooks - hook(resp, err) + if l := len(r.retryOption.RetryHooks); l > 0 { + for i := l - 1; i >= 0; i-- { // run retry hooks in reverse order + r.retryOption.RetryHooks[i](resp, err) + } } time.Sleep(r.retryOption.GetRetryInterval(resp, r.RetryAttempt))