@@ -12,7 +12,6 @@ import (
12
12
"io"
13
13
"io/ioutil"
14
14
"net/http"
15
- "net/url"
16
15
"time"
17
16
18
17
"go.uber.org/zap"
@@ -52,7 +51,7 @@ func (p *Protocol) doOnce(req *http.Request) (binding.Message, protocol.Result)
52
51
}
53
52
54
53
func (p * Protocol ) doWithRetry (ctx context.Context , params * cecontext.RetryParams , req * http.Request ) (binding.Message , error ) {
55
- then := time .Now ()
54
+ start := time .Now ()
56
55
retry := 0
57
56
results := make ([]protocol.Result , 0 )
58
57
@@ -79,51 +78,34 @@ func (p *Protocol) doWithRetry(ctx context.Context, params *cecontext.RetryParam
79
78
80
79
// Fast track common case.
81
80
if protocol .IsACK (result ) {
82
- return msg , NewRetriesResult (result , retry , then , results )
81
+ return msg , NewRetriesResult (result , retry , start , results )
83
82
}
84
83
85
- // Try again?
86
- //
87
- // Make sure the error was something we should retry.
88
-
89
- {
90
- var uErr * url .Error
91
- if errors . As ( result , & uErr ) {
92
- goto DoBackoff
84
+ var httpResult * Result
85
+ if errors . As ( result , & httpResult ) {
86
+ sc := httpResult . StatusCode
87
+ if ! p . isRetriableFunc ( sc ) {
88
+ cecontext . LoggerFrom ( ctx ). Debugw ( "status code not retryable, will not try again" ,
89
+ zap .Error ( httpResult ),
90
+ zap . Int ( "statusCode" , sc ))
91
+ return msg , NewRetriesResult ( result , retry , start , results )
93
92
}
94
93
}
95
94
96
- {
97
- var httpResult * Result
98
- if errors .As (result , & httpResult ) {
99
- sc := httpResult .StatusCode
100
- if p .isRetriableFunc (sc ) {
101
- // retry!
102
- goto DoBackoff
103
- } else {
104
- // Permanent error
105
- cecontext .LoggerFrom (ctx ).Debugw ("status code not retryable, will not try again" ,
106
- zap .Error (httpResult ),
107
- zap .Int ("statusCode" , sc ))
108
- return msg , NewRetriesResult (result , retry , then , results )
109
- }
110
- }
111
- }
112
-
113
- DoBackoff:
114
- resetBody (req , body )
115
-
116
- // Wait for the correct amount of backoff time.
117
-
118
95
// total tries = retry + 1
119
- if err : = params .Backoff (ctx , retry + 1 ); err != nil {
96
+ if err = params .Backoff (ctx , retry + 1 ); err != nil {
120
97
// do not try again.
121
98
cecontext .LoggerFrom (ctx ).Debugw ("backoff error, will not try again" , zap .Error (err ))
122
- return msg , NewRetriesResult (result , retry , then , results )
99
+ return msg , NewRetriesResult (result , retry , start , results )
123
100
}
124
101
125
102
retry ++
103
+ resetBody (req , body )
126
104
results = append (results , result )
105
+ if msg != nil {
106
+ // avoid leak, forget message, ignore error
107
+ _ = msg .Finish (nil )
108
+ }
127
109
}
128
110
}
129
111
0 commit comments