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)