From b05514b02cf851bc17c289e6d49be9487b8e619a Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Wed, 30 Jan 2019 21:38:25 +0100 Subject: [PATCH] wait for both requests to finish before changing timeout --- proxy/dokodemo/dokodemo.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/proxy/dokodemo/dokodemo.go b/proxy/dokodemo/dokodemo.go index 09cf5a68d1..cb7f87883f 100644 --- a/proxy/dokodemo/dokodemo.go +++ b/proxy/dokodemo/dokodemo.go @@ -4,6 +4,7 @@ package dokodemo import ( "context" + "sync/atomic" "time" "v2ray.com/core" @@ -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 { @@ -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) }