From 063cf111cb2f45c55fcffd1c418ff3e90c33d9ae Mon Sep 17 00:00:00 2001 From: noisyfox Date: Sat, 17 Sep 2016 16:08:51 +1000 Subject: [PATCH] Fix a bug that a TCPHandler may be shutdown immediately after creation. Becuase we put handler.Start() call after timeout check and lastActivity is initialized in Start(), this will lead to a incorrect timeout. Also because we will call handler.Start() right after the constructor and timeout check, so it makes no difference where we put the initializtion of lastActivity. We won't do this again in Start() because DateTime.Now will consumes a lot of cpu time. --- shadowsocks-csharp/Controller/Service/TCPRelay.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shadowsocks-csharp/Controller/Service/TCPRelay.cs b/shadowsocks-csharp/Controller/Service/TCPRelay.cs index 2a2b60a7..405d2795 100644 --- a/shadowsocks-csharp/Controller/Service/TCPRelay.cs +++ b/shadowsocks-csharp/Controller/Service/TCPRelay.cs @@ -173,6 +173,8 @@ namespace Shadowsocks.Controller this._config = config; this._tcprelay = tcprelay; this._connection = socket; + + lastActivity = DateTime.Now; } public void CreateRemote() @@ -195,7 +197,6 @@ namespace Shadowsocks.Controller _firstPacket = firstPacket; _firstPacketLength = length; HandshakeReceive(); - lastActivity = DateTime.Now; } private void CheckClose()