[tor-commits] [meek/main] Fix the locking around rt.rt.

dcf at torproject.org dcf at torproject.org
Thu Dec 30 05:07:32 UTC 2021


commit 46e612d2e9afd6e5dfa54c473ed17aeab49001af
Author: David Fifield <david at bamsoftware.com>
Date:   Wed Dec 29 22:06:41 2021 -0700

    Fix the locking around rt.rt.
    
    sync.Once does not prevent other goroutines from accessing a variable
    that has not been defined yet.
---
 meek-client/utls.go | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/meek-client/utls.go b/meek-client/utls.go
index 1f3effb..3bb5308 100644
--- a/meek-client/utls.go
+++ b/meek-client/utls.go
@@ -97,7 +97,7 @@ type UTLSRoundTripper struct {
 	clientHelloID *utls.ClientHelloID
 	config        *utls.Config
 	proxyDialer   proxy.Dialer
-	rtOnce        sync.Once
+	rtLock        sync.Mutex
 	rt            http.RoundTripper
 
 	// Transport for HTTP requests, which don't use uTLS.
@@ -114,12 +114,14 @@ func (rt *UTLSRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)
 		return nil, fmt.Errorf("unsupported URL scheme %q", req.URL.Scheme)
 	}
 
-	// On the first call, make an http.Transport or http2.Transport as
-	// appropriate.
 	var err error
-	rt.rtOnce.Do(func() {
+	rt.rtLock.Lock()
+	if rt.rt == nil {
+		// On the first call, make an http.Transport or http2.Transport
+		// as appropriate.
 		rt.rt, err = makeRoundTripper(req.URL, rt.clientHelloID, rt.config, rt.proxyDialer)
-	})
+	}
+	rt.rtLock.Unlock()
 	if err != nil {
 		return nil, err
 	}



More information about the tor-commits mailing list