commit 01a96c7d95bfcc6ec5b6a770c8a56ef7da6605f4 Author: David Fifield david@bamsoftware.com Date: Mon May 24 14:36:24 2021 -0600
Fix error handling around transport.Dial.
The code checked for and displayed an error, but would then go on to call copyLoop on the nil Conn returned from transport.Dial. Add a return in that case, and put the cleanup operations in defer. Also remove an obsolete comment about an empty address. Obsolete because: https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowf... --- client/snowflake.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/client/snowflake.go b/client/snowflake.go index f19afcf..bacc389 100644 --- a/client/snowflake.go +++ b/client/snowflake.go @@ -69,17 +69,15 @@ func socksAcceptLoop(ln *pt.SocksListener, transport *sf.Transport, shutdown cha
handler := make(chan struct{}) go func() { - // pass an empty address because the broker chooses the bridge + defer close(handler) sconn, err := transport.Dial() if err != nil { log.Printf("dial error: %s", err) + return } + defer sconn.Close() // copy between the created Snowflake conn and the SOCKS conn copyLoop(conn, sconn) - sconn.Close() - close(handler) - return - }() select { case <-shutdown: