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/snowflake/-/merge_requests/31#note_2733279
This commit is contained in:
David Fifield 2021-05-24 14:36:24 -06:00
parent ef4d0a1da5
commit 01a96c7d95

View file

@ -69,17 +69,15 @@ func socksAcceptLoop(ln *pt.SocksListener, transport *sf.Transport, shutdown cha
handler := make(chan struct{}) handler := make(chan struct{})
go func() { go func() {
// pass an empty address because the broker chooses the bridge defer close(handler)
sconn, err := transport.Dial() sconn, err := transport.Dial()
if err != nil { if err != nil {
log.Printf("dial error: %s", err) log.Printf("dial error: %s", err)
return
} }
defer sconn.Close()
// copy between the created Snowflake conn and the SOCKS conn // copy between the created Snowflake conn and the SOCKS conn
copyLoop(conn, sconn) copyLoop(conn, sconn)
sconn.Close()
close(handler)
return
}() }()
select { select {
case <-shutdown: case <-shutdown: