@@ -265,6 +265,16 @@ func (c *baseClient) withConn(
265
265
return err
266
266
}
267
267
268
+ // always attempt getConn to init the pool first so the following _withConn will have the valid conn for resolving hystrix
269
+ cn , connerr := c .getConn (ctx )
270
+ if connerr != nil {
271
+ return connerr
272
+ }
273
+
274
+ defer func () {
275
+ c .releaseConn (ctx , cn , connerr )
276
+ }()
277
+
268
278
err := limiter .Execute (func () error {
269
279
return c ._withConn (ctx , fn )
270
280
})
@@ -668,26 +678,26 @@ func (c *Client) pubSub() *PubSub {
668
678
// subscription may not be active immediately. To force the connection to wait,
669
679
// you may call the Receive() method on the returned *PubSub like so:
670
680
//
671
- // sub := client.Subscribe(queryResp)
672
- // iface, err := sub.Receive()
673
- // if err != nil {
674
- // // handle error
675
- // }
681
+ // sub := client.Subscribe(queryResp)
682
+ // iface, err := sub.Receive()
683
+ // if err != nil {
684
+ // // handle error
685
+ // }
676
686
//
677
- // // Should be *Subscription, but others are possible if other actions have been
678
- // // taken on sub since it was created.
679
- // switch iface.(type) {
680
- // case *Subscription:
681
- // // subscribe succeeded
682
- // case *Message:
683
- // // received first message
684
- // case *Pong:
685
- // // pong received
686
- // default:
687
- // // handle error
688
- // }
687
+ // // Should be *Subscription, but others are possible if other actions have been
688
+ // // taken on sub since it was created.
689
+ // switch iface.(type) {
690
+ // case *Subscription:
691
+ // // subscribe succeeded
692
+ // case *Message:
693
+ // // received first message
694
+ // case *Pong:
695
+ // // pong received
696
+ // default:
697
+ // // handle error
698
+ // }
689
699
//
690
- // ch := sub.Channel()
700
+ // ch := sub.Channel()
691
701
func (c * Client ) Subscribe (ctx context.Context , channels ... string ) * PubSub {
692
702
pubsub := c .pubSub ()
693
703
if len (channels ) > 0 {
0 commit comments