[tor-commits] [snowflake/main] Fix datarace for Peers.melted

cohosh at torproject.org cohosh at torproject.org
Thu Jun 24 15:56:19 UTC 2021


commit bb7ff6180bf2cb9553db8cbb4600092107cf9303
Author: Cecylia Bocovich <cohosh at torproject.org>
Date:   Thu Jun 17 17:42:22 2021 -0400

    Fix datarace for Peers.melted
    
    Using the boolean value was unnecessary since we already have a channel
    we can check for closure.
---
 client/lib/peers.go | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/client/lib/peers.go b/client/lib/peers.go
index 6fa2d29..66373f1 100644
--- a/client/lib/peers.go
+++ b/client/lib/peers.go
@@ -26,8 +26,7 @@ type Peers struct {
 	snowflakeChan chan *WebRTCPeer
 	activePeers   *list.List
 
-	melt   chan struct{}
-	melted bool
+	melt chan struct{}
 
 	collection sync.WaitGroup
 }
@@ -51,8 +50,10 @@ func (p *Peers) Collect() (*WebRTCPeer, error) {
 	// Engage the Snowflake Catching interface, which must be available.
 	p.collection.Add(1)
 	defer p.collection.Done()
-	if p.melted {
+	select {
+	case <-p.melt:
 		return nil, fmt.Errorf("Snowflakes have melted")
+	default:
 	}
 	if nil == p.Tongue {
 		return nil, errors.New("missing Tongue to catch Snowflakes with")
@@ -120,7 +121,6 @@ func (p *Peers) purgeClosedPeers() {
 // Close all Peers contained here.
 func (p *Peers) End() {
 	close(p.melt)
-	p.melted = true
 	p.collection.Wait()
 	close(p.snowflakeChan)
 	cnt := p.Count()





More information about the tor-commits mailing list