Skip to content

Commit

Permalink
wait for both requests to finish before changing timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
DarienRaymond committed Jan 30, 2019
1 parent e33e450 commit b05514b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion proxy/dokodemo/dokodemo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package dokodemo

import (
"context"
"sync/atomic"
"time"

"v2ray.com/core"
Expand Down Expand Up @@ -106,8 +107,13 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
return newError("failed to dispatch request").Base(err)
}

requestCount := int32(1)
requestDone := func() error {
defer timer.SetTimeout(plcy.Timeouts.DownlinkOnly)
defer func() {
if atomic.AddInt32(&requestCount, -1) == 0 {
timer.SetTimeout(plcy.Timeouts.DownlinkOnly)
}
}()

reader := buf.NewReader(conn)
if err := buf.Copy(reader, link.Writer, buf.UpdateActivity(timer)); err != nil {
Expand Down Expand Up @@ -144,7 +150,13 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in

writer = &buf.SequentialWriter{Writer: tConn}
tReader := buf.NewReader(tConn)
requestCount++
tproxyRequest = func() error {
defer func() {
if atomic.AddInt32(&requestCount, -1) == 0 {
timer.SetTimeout(plcy.Timeouts.DownlinkOnly)
}
}()
if err := buf.Copy(tReader, link.Writer, buf.UpdateActivity(timer)); err != nil {
return newError("failed to transport request (TPROXY conn)").Base(err)
}
Expand Down

0 comments on commit b05514b

Please sign in to comment.