Browse Source

Avoid beeing stuck in hub lock when a client gets replaced but the old connection does not hang on close.

pull/182/head
Simon Eisenmann 11 years ago
parent
commit
c49331bd7d
  1. 8
      src/app/spreed-webrtc-server/hub.go

8
src/app/spreed-webrtc-server/hub.go

@ -154,8 +154,12 @@ func (h *hub) OnConnect(client Client, session *Session) { @@ -154,8 +154,12 @@ func (h *hub) OnConnect(client Client, session *Session) {
log.Printf("Created client %d with id %s\n", client.Index(), session.Id)
// Register connection or replace existing one.
if ec, ok := h.clients[session.Id]; ok {
log.Printf("Closing obsolete client %d with id %s\n", ec.Index(), session.Id)
ec.ReplaceAndClose()
// Clean up old client at the end and make sure to run this in another go routine,
// to avoid blocking the new client if the old one hangs or whatever.
defer func() {
log.Printf("Closing obsolete client %d with id %s\n", ec.Index(), session.Id)
go ec.ReplaceAndClose()
}()
}
h.clients[session.Id] = client
h.mutex.Unlock()

Loading…
Cancel
Save