From 7aa977d2fe37fd43a804a1ae00a14a535b4b5d5f Mon Sep 17 00:00:00 2001 From: William Petit Date: Fri, 23 Oct 2020 13:42:18 +0200 Subject: [PATCH] feat: cleanup remote client on connection closed --- remote_client.go | 6 ++++++ server.go | 1 + 2 files changed, 7 insertions(+) diff --git a/remote_client.go b/remote_client.go index 6b75d41..f1a7c04 100644 --- a/remote_client.go +++ b/remote_client.go @@ -125,6 +125,12 @@ func (c *RemoteClient) Proxy(ctx context.Context, network, address string) (net. return c.control.Proxy(ctx, network, address) } +func (c *RemoteClient) Close() { + if c.sess != nil && !c.sess.IsClosed() { + c.sess.Close() + } +} + func NewRemoteClient() *RemoteClient { return &RemoteClient{} } diff --git a/server.go b/server.go index 2eff4de..6a13ded 100644 --- a/server.go +++ b/server.go @@ -37,6 +37,7 @@ func (s *Server) handleNewConn(ctx context.Context, conn *kcp.UDPSession) { ctx = logger.With(ctx, logger.F("remoteAddr", conn.RemoteAddr().String())) remoteClient := NewRemoteClient() + defer remoteClient.Close() remoteClient.ConfigureHooks(s.conf.Hooks)