diff --git a/protocol/connections/connectionsmanager.go b/protocol/connections/connectionsmanager.go index 5c69473..0f299d6 100644 --- a/protocol/connections/connectionsmanager.go +++ b/protocol/connections/connectionsmanager.go @@ -45,13 +45,17 @@ func (m *Manager) ManagePeerConnection(host string, engine *Engine) *PeerPeerCon func (m *Manager) ManageServerConnection(host string, handler func(string, *protocol.GroupMessage)) { m.lock.Lock() - _, exists := m.serverConnections[host] - if !exists { - psc := NewPeerServerConnection(m.acn, host) - go psc.Run() - psc.GroupMessageHandler = handler - m.serverConnections[host] = psc + psc, exists := m.serverConnections[host] + + newPsc := NewPeerServerConnection(m.acn, host) + newPsc.GroupMessageHandler = handler + go newPsc.Run() + m.serverConnections[host] = newPsc + + if exists { + psc.Close() } + m.lock.Unlock() }