diff options
author | Yawning Angel <yawning@schwanenlied.me> | 2014-05-12 05:08:04 +0000 |
---|---|---|
committer | Yawning Angel <yawning@schwanenlied.me> | 2014-05-12 05:08:04 +0000 |
commit | c3acefb7e5aa5ef4cd65fc77ad4caa917efda130 (patch) | |
tree | 256969a3d569a7b49cae4698cf5da6e9dfd1b04c /obfs4proxy | |
parent | 433ff8027d32bc856b7da5d227bc711d99c5290d (diff) |
Log and propagate errors between the 2 goroutines in copyLoop.
This fixes #1.
Diffstat (limited to 'obfs4proxy')
-rw-r--r-- | obfs4proxy/obfs4proxy.go | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/obfs4proxy/obfs4proxy.go b/obfs4proxy/obfs4proxy.go index dc0c2bc..34027fc 100644 --- a/obfs4proxy/obfs4proxy.go +++ b/obfs4proxy/obfs4proxy.go @@ -81,11 +81,21 @@ func copyLoop(a, b net.Conn) { // XXX: Log/propagate errors. go func() { - io.Copy(b, a) + _, err := io.Copy(b, a) + if err != nil { + b.Close() + a.Close() + log.Printf("[WARN] Connection closed: %s", err) + } wg.Done() }() go func() { - io.Copy(a, b) + _, err := io.Copy(a, b) + if err != nil { + a.Close() + b.Close() + log.Printf("[WARN] Connection closed: %s", err) + } wg.Done() }() @@ -115,7 +125,7 @@ func serverHandler(conn net.Conn, info *pt.ServerInfo) error { } defer or.Close() - copyLoop(conn, or) + copyLoop(or, conn) return nil } |