@@ -265,25 +265,39 @@ func (c *baseClient) withConn(
265
265
return err
266
266
}
267
267
268
- // Request is allowed occasionally to close the cb and cb is still in open state
269
- // Init the connection to avoid nested hystrix call during connection establishment
268
+ err := c .executeWithCircuitBreaker (ctx , fn , limiter )
269
+ limiter .ReportResult (err )
270
+ return err
271
+ }
272
+
273
+ func (c * baseClient ) executeWithCircuitBreaker (
274
+ ctx context.Context ,
275
+ fn func (context.Context , * pool.Conn ) error ,
276
+ limiter Limiter ,
277
+ ) error {
278
+ // When circuit is open, try to establish connection first
279
+ // This is needed for circuit breaker recovery
270
280
if limiter .IsCBOpen () {
271
- cn , err := c .getConn (ctx )
272
- if err != nil {
281
+ if err := c .preConnect (ctx ); err != nil {
273
282
return err
274
283
}
275
-
276
- defer func () {
277
- c .releaseConn (ctx , cn , err )
278
- }()
279
284
}
280
285
281
- err := limiter .Execute (func () error {
286
+ return limiter .Execute (func () error {
282
287
return c ._withConn (ctx , fn )
283
288
})
289
+ }
284
290
285
- limiter .ReportResult (err )
286
- return err
291
+ func (c * baseClient ) preConnect (ctx context.Context ) error {
292
+ cn , err := c .getConn (ctx )
293
+ if err != nil {
294
+ return err
295
+ }
296
+
297
+ defer func () {
298
+ c .releaseConn (ctx , cn , err )
299
+ }()
300
+ return nil
287
301
}
288
302
289
303
func (c * baseClient ) _withConn (
0 commit comments