Browse Source

Fixed an issue where replaced sessions cannot receive data from contacts in other rooms.

release-0.23
Simon Eisenmann 10 years ago
parent
commit
d5323d2610
  1. 18
      src/app/spreed-webrtc-server/client.go
  2. 8
      src/app/spreed-webrtc-server/hub.go
  3. 27
      src/app/spreed-webrtc-server/session.go

18
src/app/spreed-webrtc-server/client.go

@ -43,7 +43,7 @@ type Client interface {
Session() *Session Session() *Session
Index() uint64 Index() uint64
Close() Close()
ReplaceAndClose() ReplaceAndClose(Client)
} }
type client struct { type client struct {
@ -87,9 +87,15 @@ func (client *client) Session() *Session {
return client.session return client.session
} }
func (client *client) ReplaceAndClose() { func (client *client) ReplaceAndClose(oldClient Client) {
client.session.Close() oldSession := oldClient.Session()
if client.Connection != nil { client.session.Replace(oldSession)
client.Connection.Close() go func() {
} // Close old session and client in another go routine,
// to avoid blocking the new client if the old one hangs or
// whatever.
log.Printf("Closing obsolete client %d (replaced with %d) with id %s\n", oldClient.Index(), client.Index(), oldSession.Id)
oldSession.Close()
oldClient.Close()
}()
} }

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

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

27
src/app/spreed-webrtc-server/session.go

@ -56,6 +56,7 @@ type Session struct {
subscriptions map[string]*Session subscriptions map[string]*Session
subscribers map[string]*Session subscribers map[string]*Session
disconnected bool disconnected bool
replaced bool
} }
func NewSession(manager SessionManager, unicaster Unicaster, broadcaster Broadcaster, rooms RoomStatusManager, buddyImages ImageCache, attestations *securecookie.SecureCookie, id, sid string) *Session { func NewSession(manager SessionManager, unicaster Unicaster, broadcaster Broadcaster, rooms RoomStatusManager, buddyImages ImageCache, attestations *securecookie.SecureCookie, id, sid string) *Session {
@ -209,6 +210,9 @@ func (s *Session) Close() {
return return
} }
// TODO(longsleep): Verify that it is ok to not do all this when replaced is true.
if !s.replaced {
outgoing := &DataOutgoing{ outgoing := &DataOutgoing{
From: s.Id, From: s.Id,
A: s.attestation.Token(), A: s.attestation.Token(),
@ -237,6 +241,8 @@ func (s *Session) Close() {
s.SessionManager.DestroySession(s.Id, s.userid) s.SessionManager.DestroySession(s.Id, s.userid)
s.buddyImages.Delete(s.Id) s.buddyImages.Delete(s.Id)
}
s.subscriptions = make(map[string]*Session) s.subscriptions = make(map[string]*Session)
s.subscribers = make(map[string]*Session) s.subscribers = make(map[string]*Session)
s.disconnected = true s.disconnected = true
@ -244,6 +250,27 @@ func (s *Session) Close() {
s.mutex.Unlock() s.mutex.Unlock()
} }
func (s *Session) Replace(oldSession *Session) {
oldSession.mutex.Lock()
if oldSession.disconnected {
oldSession.mutex.Unlock()
return
}
s.mutex.Lock()
s.subscriptions = oldSession.subscriptions
s.subscribers = oldSession.subscribers
s.mutex.Unlock()
// Mark old session as replaced.
oldSession.replaced = true
oldSession.mutex.Unlock()
}
func (s *Session) Update(update *SessionUpdate) uint64 { func (s *Session) Update(update *SessionUpdate) uint64 {
s.mutex.Lock() s.mutex.Lock()
defer s.mutex.Unlock() defer s.mutex.Unlock()

Loading…
Cancel
Save