From eb9777a6f878e687bdc888d18b6c61b2ff4e9cac Mon Sep 17 00:00:00 2001 From: yuriy0803 <68668177+yuriy0803@users.noreply.github.com> Date: Tue, 23 Jul 2024 13:46:05 +0200 Subject: [PATCH] Connection time for 2024/07/23 13:44:49 Error reading from socket: read tcp 192.168.178.41:8008->192.168.178.8:59614: read: connection reset by peer 2024/07/23 13:44:49 Error handling TCP client 192.168.178.8: read tcp 192.168.178.41:8008->192.168.178.8:59614: read: connection reset by peer 2024/07/23 13:44:49 Connection time for 192.168.178.8: 1m27.808454138s --- proxy/stratum.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/proxy/stratum.go b/proxy/stratum.go index 6ea714a..af14b15 100644 --- a/proxy/stratum.go +++ b/proxy/stratum.go @@ -76,16 +76,26 @@ func (s *ProxyServer) ListenTCP() { accept <- n go func(cs *Session) { - err = s.handleTCPClient(cs) - if err != nil { - s.removeSession(cs) - conn.Close() - } + s.logConnectionTime(cs) <-accept }(cs) } } +func (s *ProxyServer) logConnectionTime(cs *Session) { + start := time.Now() + defer func() { + duration := time.Since(start) + log.Printf("Connection time for %s: %s", cs.ip, duration) + }() + err := s.handleTCPClient(cs) + if err != nil { + log.Printf("Error handling TCP client %s: %v", cs.ip, err) + s.removeSession(cs) + cs.conn.Close() + } +} + func (s *ProxyServer) handleTCPClient(cs *Session) error { cs.enc = json.NewEncoder(cs.conn) connbuff := bufio.NewReaderSize(cs.conn, MaxReqSize)