From 798212b311aa23526908af32c251440351a9c1ab Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Fri, 23 Feb 2018 17:07:45 +0100 Subject: [PATCH] fix timer settings --- proxy/http/server.go | 4 +++- proxy/shadowsocks/server.go | 7 ++++--- proxy/socks/server.go | 7 +++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/proxy/http/server.go b/proxy/http/server.go index 6668c03f8..48e0520f9 100644 --- a/proxy/http/server.go +++ b/proxy/http/server.go @@ -192,11 +192,13 @@ func (s *Server) handleConnect(ctx context.Context, request *http.Request, reade }) responseDone := signal.ExecuteAsync(func() error { + defer timer.SetTimeout(s.policy().Timeouts.UplinkOnly) + v2writer := buf.NewWriter(conn) if err := buf.Copy(ray.InboundOutput(), v2writer, buf.UpdateActivity(timer)); err != nil { return err } - timer.SetTimeout(s.policy().Timeouts.UplinkOnly) + return nil }) diff --git a/proxy/shadowsocks/server.go b/proxy/shadowsocks/server.go index 63e3f2a04..8aacd2eb3 100644 --- a/proxy/shadowsocks/server.go +++ b/proxy/shadowsocks/server.go @@ -171,6 +171,8 @@ func (s *Server) handleConnection(ctx context.Context, conn internet.Connection, } responseDone := signal.ExecuteAsync(func() error { + defer timer.SetTimeout(sessionPolicy.Timeouts.UplinkOnly) + bufferedWriter := buf.NewBufferedWriter(buf.NewWriter(conn)) responseWriter, err := WriteTCPResponse(request, bufferedWriter) if err != nil { @@ -194,18 +196,17 @@ func (s *Server) handleConnection(ctx context.Context, conn internet.Connection, return newError("failed to transport all TCP response").Base(err) } - timer.SetTimeout(sessionPolicy.Timeouts.UplinkOnly) - return nil }) requestDone := signal.ExecuteAsync(func() error { + defer timer.SetTimeout(sessionPolicy.Timeouts.DownlinkOnly) defer ray.InboundInput().Close() if err := buf.Copy(bodyReader, ray.InboundInput(), buf.UpdateActivity(timer)); err != nil { return newError("failed to transport all TCP request").Base(err) } - timer.SetTimeout(sessionPolicy.Timeouts.DownlinkOnly) + return nil }) diff --git a/proxy/socks/server.go b/proxy/socks/server.go index 181e47449..6f61df942 100644 --- a/proxy/socks/server.go +++ b/proxy/socks/server.go @@ -131,22 +131,25 @@ func (v *Server) transport(ctx context.Context, reader io.Reader, writer io.Writ output := ray.InboundOutput() requestDone := signal.ExecuteAsync(func() error { + defer timer.SetTimeout(v.policy().Timeouts.DownlinkOnly) defer input.Close() v2reader := buf.NewReader(reader) if err := buf.Copy(v2reader, input, buf.UpdateActivity(timer)); err != nil { return newError("failed to transport all TCP request").Base(err) } - timer.SetTimeout(v.policy().Timeouts.DownlinkOnly) + return nil }) responseDone := signal.ExecuteAsync(func() error { + defer timer.SetTimeout(v.policy().Timeouts.UplinkOnly) + v2writer := buf.NewWriter(writer) if err := buf.Copy(output, v2writer, buf.UpdateActivity(timer)); err != nil { return newError("failed to transport all TCP response").Base(err) } - timer.SetTimeout(v.policy().Timeouts.UplinkOnly) + return nil })