diff options
| author | David Fifield <david@bamsoftware.com> | 2020-02-21 14:47:34 -0700 |
|---|---|---|
| committer | David Fifield <david@bamsoftware.com> | 2020-02-21 20:36:07 -0700 |
| commit | 6b902fcad0437d2d92696a1ccc7801091d3ef667 (patch) | |
| tree | 254d4826498e10be10f593a18206c12c9ee413a1 | |
| parent | da37211c74b7d6992f4cb07adb6033a684d56838 (diff) | |
Let copyLoop exit when either direction finishes.
Formerly we waiting until *both* directions finished. What this meant in
practice is that when the remote connection ended, copyLoop would become
useless but would continue blocking its caller until something else
finally closed the socks connection.
| -rw-r--r-- | client/lib/snowflake.go | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/client/lib/snowflake.go b/client/lib/snowflake.go index 01dc448..671ef5d 100644 --- a/client/lib/snowflake.go +++ b/client/lib/snowflake.go @@ -7,7 +7,6 @@ import ( "io" "log" "net" - "sync" "time" "git.torproject.org/pluggable-transports/snowflake.git/common/turbotunnel" @@ -94,20 +93,19 @@ func Handler(socks net.Conn, snowflakes SnowflakeCollector) error { // Exchanges bytes between two ReadWriters. // (In this case, between a SOCKS and WebRTC connection.) func copyLoop(socks, webRTC io.ReadWriter) { - var wg sync.WaitGroup - wg.Add(2) + done := make(chan struct{}, 2) go func() { if _, err := io.Copy(socks, webRTC); err != nil { log.Printf("copying WebRTC to SOCKS resulted in error: %v", err) } - wg.Done() + done <- struct{}{} }() go func() { if _, err := io.Copy(webRTC, socks); err != nil { log.Printf("copying SOCKS to WebRTC resulted in error: %v", err) } - wg.Done() + done <- struct{}{} }() - wg.Wait() + <-done log.Println("copy loop ended") } |
