Skip to content

Commit

Permalink
Wait a short while before disrupting copy in relay
Browse files Browse the repository at this point in the history
The short wait period allows sending remaining bytes in the other direction.
  • Loading branch information
riobard committed Aug 19, 2020
1 parent 60c7f85 commit 83d899e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,16 @@ func tcpRemote(addr string, shadow func(net.Conn) net.Conn) {
func relay(left, right net.Conn) error {
var err, err1 error
var wg sync.WaitGroup

var wait = 5 * time.Second
wg.Add(1)
go func() {
defer wg.Done()
_, err1 = io.Copy(right, left)
right.SetReadDeadline(time.Now()) // unblock read on right
right.SetReadDeadline(time.Now().Add(wait)) // unblock read on right
}()

_, err = io.Copy(left, right)
left.SetReadDeadline(time.Now()) // unblock read on left
left.SetReadDeadline(time.Now().Add(wait)) // unblock read on left
wg.Wait()

if err1 != nil {
Expand Down

0 comments on commit 83d899e

Please sign in to comment.