mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Perform SnowflakeConn.Close() logic only once
Use synchronization to avoid a panic if SnowflakeConn.Close is called more than once.
This commit is contained in:
parent
028ff82683
commit
a019fdaec9
1 changed files with 16 additions and 13 deletions
|
@ -29,6 +29,7 @@ type Peers struct {
|
||||||
melt chan struct{}
|
melt chan struct{}
|
||||||
|
|
||||||
collectLock sync.Mutex
|
collectLock sync.Mutex
|
||||||
|
closeOnce sync.Once
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPeers constructs a fresh container of remote peers.
|
// NewPeers constructs a fresh container of remote peers.
|
||||||
|
@ -122,17 +123,19 @@ func (p *Peers) purgeClosedPeers() {
|
||||||
// End closes all active connections to Peers contained here, and stops the
|
// End closes all active connections to Peers contained here, and stops the
|
||||||
// collection of future Peers.
|
// collection of future Peers.
|
||||||
func (p *Peers) End() {
|
func (p *Peers) End() {
|
||||||
close(p.melt)
|
p.closeOnce.Do(func() {
|
||||||
p.collectLock.Lock()
|
close(p.melt)
|
||||||
defer p.collectLock.Unlock()
|
p.collectLock.Lock()
|
||||||
close(p.snowflakeChan)
|
defer p.collectLock.Unlock()
|
||||||
cnt := p.Count()
|
close(p.snowflakeChan)
|
||||||
for e := p.activePeers.Front(); e != nil; {
|
cnt := p.Count()
|
||||||
next := e.Next()
|
for e := p.activePeers.Front(); e != nil; {
|
||||||
conn := e.Value.(*WebRTCPeer)
|
next := e.Next()
|
||||||
conn.Close()
|
conn := e.Value.(*WebRTCPeer)
|
||||||
p.activePeers.Remove(e)
|
conn.Close()
|
||||||
e = next
|
p.activePeers.Remove(e)
|
||||||
}
|
e = next
|
||||||
log.Printf("WebRTC: melted all %d snowflakes.", cnt)
|
}
|
||||||
|
log.Printf("WebRTC: melted all %d snowflakes.", cnt)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue