mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Fix datarace for WebRTCPeer.closed
The race condition occurs because concurrent goroutines are intermixing reads and writes of `WebRTCPeer.closed`. Spotted when integrating Snowflake inside OONI in https://github.com/ooni/probe-cli/pull/373.
This commit is contained in:
parent
ed2d5df87d
commit
ddcdfc4f09
3 changed files with 23 additions and 11 deletions
|
|
@ -83,7 +83,7 @@ func (p *Peers) Pop() *WebRTCPeer {
|
|||
if !ok {
|
||||
return nil
|
||||
}
|
||||
if snowflake.closed {
|
||||
if snowflake.Closed() {
|
||||
continue
|
||||
}
|
||||
// Set to use the same rate-limited traffic logger to keep consistency.
|
||||
|
|
@ -110,7 +110,7 @@ func (p *Peers) purgeClosedPeers() {
|
|||
next := e.Next()
|
||||
conn := e.Value.(*WebRTCPeer)
|
||||
// Purge those marked for deletion.
|
||||
if conn.closed {
|
||||
if conn.Closed() {
|
||||
p.activePeers.Remove(e)
|
||||
}
|
||||
e = next
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue