mirror of
https://github.com/jech/galene.git
synced 2024-11-22 16:45:58 +01:00
Avoid calling pc.Close under a lock.
Apparently Close can take unbounded amounts of time.
This commit is contained in:
parent
13d6b7ad1f
commit
bd5cd7c1a2
1 changed files with 32 additions and 16 deletions
|
@ -284,53 +284,70 @@ func addDownConn(c *webClient, id string, remote conn.Up) (*rtpDownConnection, e
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = addDownConnHelper(c, conn, remote)
|
||||||
|
if err != nil {
|
||||||
|
conn.pc.Close()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return conn, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func addDownConnHelper(c *webClient, conn *rtpDownConnection, remote conn.Up) (error) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
|
|
||||||
if c.up != nil && c.up[id] != nil {
|
if c.up != nil && c.up[conn.id] != nil {
|
||||||
conn.pc.Close()
|
return errors.New("Adding duplicate connection")
|
||||||
return nil, errors.New("Adding duplicate connection")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.down == nil {
|
if c.down == nil {
|
||||||
c.down = make(map[string]*rtpDownConnection)
|
c.down = make(map[string]*rtpDownConnection)
|
||||||
}
|
}
|
||||||
|
|
||||||
old := c.down[id]
|
old := c.down[conn.id]
|
||||||
if old != nil {
|
if old != nil {
|
||||||
old.pc.Close()
|
// Avoid calling Close under a lock
|
||||||
|
go old.pc.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.pc.OnICECandidate(func(candidate *webrtc.ICECandidate) {
|
conn.pc.OnICECandidate(func(candidate *webrtc.ICECandidate) {
|
||||||
sendICE(c, id, candidate)
|
sendICE(c, conn.id, candidate)
|
||||||
})
|
})
|
||||||
|
|
||||||
conn.pc.OnICEConnectionStateChange(func(state webrtc.ICEConnectionState) {
|
conn.pc.OnICEConnectionStateChange(func(state webrtc.ICEConnectionState) {
|
||||||
if state == webrtc.ICEConnectionStateFailed {
|
if state == webrtc.ICEConnectionStateFailed {
|
||||||
c.action(connectionFailedAction{id: id})
|
c.action(connectionFailedAction{id: conn.id})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
err = remote.AddLocal(conn)
|
err := remote.AddLocal(conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
conn.pc.Close()
|
return err
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.down[id] = conn
|
c.down[conn.id] = conn
|
||||||
return conn, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func delDownConn(c *webClient, id string) bool {
|
func delDownConn(c *webClient, id string) bool {
|
||||||
|
conn := delDownConnHelper(c, id)
|
||||||
|
if conn != nil {
|
||||||
|
conn.pc.Close()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func delDownConnHelper(c *webClient, id string) *rtpDownConnection {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
|
|
||||||
if c.down == nil {
|
if c.down == nil {
|
||||||
return false
|
return nil
|
||||||
}
|
}
|
||||||
conn := c.down[id]
|
conn := c.down[id]
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
return false
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.remote.DelLocal(conn)
|
conn.remote.DelLocal(conn)
|
||||||
|
@ -339,9 +356,8 @@ func delDownConn(c *webClient, id string) bool {
|
||||||
// ignore errors here.
|
// ignore errors here.
|
||||||
track.remote.DelLocal(track)
|
track.remote.DelLocal(track)
|
||||||
}
|
}
|
||||||
conn.pc.Close()
|
|
||||||
delete(c.down, id)
|
delete(c.down, id)
|
||||||
return true
|
return conn
|
||||||
}
|
}
|
||||||
|
|
||||||
func addDownTrack(c *webClient, conn *rtpDownConnection, remoteTrack conn.UpTrack, remoteConn conn.Up) (*webrtc.RTPSender, error) {
|
func addDownTrack(c *webClient, conn *rtpDownConnection, remoteTrack conn.UpTrack, remoteConn conn.Up) (*webrtc.RTPSender, error) {
|
||||||
|
|
Loading…
Reference in a new issue