Skip to content

Commit 5758f57

Browse files
authored
Fix: fix deadlock when close client multi times (#817)
* Fix: fix deadlock when close client multi times * Fix: Rename isClose to isClosed
1 parent 310a828 commit 5758f57

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

clients/config_client/config_client.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type ConfigClient struct {
6060
cacheMap cache.ConcurrentMap
6161
uid string
6262
listenExecute chan struct{}
63+
isClosed bool
6364
}
6465

6566
type cacheData struct {
@@ -364,8 +365,15 @@ func (client *ConfigClient) SearchConfig(param vo.SearchConfigParam) (*model.Con
364365
}
365366

366367
func (client *ConfigClient) CloseClient() {
368+
client.mutex.Lock()
369+
defer client.mutex.Unlock()
370+
371+
if client.isClosed {
372+
return
373+
}
367374
client.configProxy.getRpcClient(client).Shutdown()
368375
client.cancel()
376+
client.isClosed = true
369377
}
370378

371379
func (client *ConfigClient) searchConfigInner(param vo.SearchConfigParam) (*model.ConfigPage, error) {

clients/naming_client/naming_client.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"math"
2323
"math/rand"
2424
"strings"
25+
"sync"
2526
"time"
2627

2728
"github.com/pkg/errors"
@@ -43,6 +44,8 @@ type NamingClient struct {
4344
cancel context.CancelFunc
4445
serviceProxy naming_proxy.INamingProxy
4546
serviceInfoHolder *naming_cache.ServiceInfoHolder
47+
isClosed bool
48+
mutex sync.Mutex
4649
}
4750

4851
// NewNamingClient ...
@@ -356,6 +359,13 @@ func (sc *NamingClient) ServerHealthy() bool {
356359

357360
// CloseClient ...
358361
func (sc *NamingClient) CloseClient() {
362+
sc.mutex.Lock()
363+
defer sc.mutex.Unlock()
364+
365+
if sc.isClosed {
366+
return
367+
}
359368
sc.serviceProxy.CloseClient()
360369
sc.cancel()
370+
sc.isClosed = true
361371
}

0 commit comments

Comments
 (0)