mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-14 10:10:42 -07:00
Fix data races
This commit is contained in:
@@ -578,12 +578,14 @@ func (c *client) clearConnection() {
|
||||
}
|
||||
|
||||
func (c *client) closeConnection() {
|
||||
c.mu.Lock()
|
||||
if c.conn == nil {
|
||||
c.mu.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
Debug("Client connection closed", clientConnStr(c.conn), c.cid)
|
||||
|
||||
c.mu.Lock()
|
||||
c.clearAuthTimer()
|
||||
c.clearPingTimer()
|
||||
c.clearConnection()
|
||||
|
||||
@@ -418,12 +418,19 @@ func TestClientMapRemoval(t *testing.T) {
|
||||
s, c, _ := setupClient()
|
||||
c.conn.Close()
|
||||
end := time.Now().Add(1 * time.Second)
|
||||
|
||||
for time.Now().Before(end) {
|
||||
if len(s.clients) > 0 {
|
||||
s.mu.Lock()
|
||||
lsc := len(s.clients)
|
||||
s.mu.Unlock()
|
||||
if lsc > 0 {
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
if len(s.clients) > 0 {
|
||||
s.mu.Lock()
|
||||
lsc := len(s.clients)
|
||||
s.mu.Unlock()
|
||||
if lsc > 0 {
|
||||
t.Fatal("Client still in server map")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user