Fix data races

This commit is contained in:
Derek Collison
2013-06-11 22:32:17 -07:00
parent 94a7d5586e
commit ef2902eef2
2 changed files with 12 additions and 3 deletions

View File

@@ -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()

View File

@@ -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")
}
}