@@ -108,6 +108,9 @@ func (s *Sentinel) dispatch(ctx context.Context, sentinel string, timeout time.D
108108
109109func (s * Sentinel ) subscribeCommand (client * Client , sentinel string ,
110110 onSubscribed func ()) error {
111+ defer func () {
112+ client .Close ()
113+ }()
111114 var channels = []interface {}{"+switch-master" }
112115 go func () {
113116 client .Send ("SUBSCRIBE" , channels ... )
@@ -219,6 +222,11 @@ func (s *Sentinel) Subscribe(sentinels []string, timeout time.Duration, onMajori
219222}
220223
221224func (s * Sentinel ) existsCommand (client * Client , names []string ) (map [string ]bool , error ) {
225+ defer func () {
226+ if ! client .isRecyclable () {
227+ client .Close ()
228+ }
229+ }()
222230 go func () {
223231 for _ , name := range names {
224232 client .Send ("SENTINEL" , "get-master-addr-by-name" , name )
@@ -239,6 +247,11 @@ func (s *Sentinel) existsCommand(client *Client, names []string) (map[string]boo
239247}
240248
241249func (s * Sentinel ) slavesCommand (client * Client , names []string ) (map [string ][]map [string ]string , error ) {
250+ defer func () {
251+ if ! client .isRecyclable () {
252+ client .Close ()
253+ }
254+ }()
242255 exists , err := s .existsCommand (client , names )
243256 if err != nil {
244257 return nil , err
@@ -279,6 +292,11 @@ func (s *Sentinel) slavesCommand(client *Client, names []string) (map[string][]m
279292}
280293
281294func (s * Sentinel ) mastersCommand (client * Client ) (map [int ]map [string ]string , error ) {
295+ defer func () {
296+ if ! client .isRecyclable () {
297+ client .Close ()
298+ }
299+ }()
282300 values , err := redigo .Values (client .Do ("SENTINEL" , "masters" ))
283301 if err != nil {
284302 return nil , errors .Trace (err )
@@ -417,6 +435,11 @@ type MonitorConfig struct {
417435}
418436
419437func (s * Sentinel ) monitorGroupsCommand (client * Client , sentniel string , config * MonitorConfig , groups map [int ]* net.TCPAddr ) error {
438+ defer func () {
439+ if ! client .isRecyclable () {
440+ client .Close ()
441+ }
442+ }()
420443 var names []string
421444 for gid := range groups {
422445 names = append (names , s .NodeName (gid ))
@@ -562,6 +585,11 @@ func (s *Sentinel) MonitorGroups(sentinels []string, timeout time.Duration, conf
562585}
563586
564587func (s * Sentinel ) removeCommand (client * Client , names []string ) error {
588+ defer func () {
589+ if ! client .isRecyclable () {
590+ client .Close ()
591+ }
592+ }()
565593 exists , err := s .existsCommand (client , names )
566594 if err != nil {
567595 return err
@@ -708,6 +736,11 @@ type SentinelGroup struct {
708736}
709737
710738func (s * Sentinel ) MastersAndSlavesClient (client * Client ) (map [string ]* SentinelGroup , error ) {
739+ defer func () {
740+ if ! client .isRecyclable () {
741+ client .Close ()
742+ }
743+ }()
711744 masters , err := s .mastersCommand (client )
712745 if err != nil {
713746 return nil , err
0 commit comments