From 327c81a0907e35bff3c6310bf820bd7e4551777e Mon Sep 17 00:00:00 2001 From: Crypto89 Date: Mon, 24 Jul 2017 21:46:39 +0200 Subject: [PATCH] PR #321: Cleanup TCP proxy connection This patch updates the conns map when the connection is closed. --- proxy/tcp/server.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/proxy/tcp/server.go b/proxy/tcp/server.go index 69d8c6e95..ab2564a8e 100644 --- a/proxy/tcp/server.go +++ b/proxy/tcp/server.go @@ -80,7 +80,20 @@ func (s *Server) Serve(l net.Listener) error { } s.conns[c] = true s.mu.Unlock() - go s.Handler.ServeTCP(c) + + go func() { + defer func() { + // Explicitly close the connection + c.Close() + + // Delete the connection from the conns map + s.mu.Lock() + delete(s.conns, c) + s.mu.Unlock() + }() + + s.Handler.ServeTCP(c) + }() } }