fix(mtcp,mws,mtls): close dead session's base conn before dropping it

Dial() deleted a dead muxSession without closing session.conn, leaking
the base TCP conn on every dead session (and, once a p2p base conn is
injected, leaking the plugin-side tunnel). session.Close() is a no-op
when session.session is nil, so the base conn is closed explicitly.
This commit is contained in:
ginuerzh
2026-09-05 16:39:27 +08:00
parent dac42ba39c
commit c210b74106
3 changed files with 12 additions and 0 deletions
+4
View File
@@ -61,6 +61,10 @@ func (d *mtcpDialer) Dial(ctx context.Context, addr string, opts ...dialer.DialO
session, ok := d.sessions[addr]
if session != nil && session.IsClosed() {
session.Close()
if session.conn != nil {
session.conn.Close() // base conn would otherwise leak (and hold a p2p tunnel open)
}
delete(d.sessions, addr) // session is dead
ok = false
}
+4
View File
@@ -62,6 +62,10 @@ func (d *mtlsDialer) Dial(ctx context.Context, addr string, opts ...dialer.DialO
session, ok := d.sessions[addr]
if session != nil && session.IsClosed() {
session.Close()
if session.conn != nil {
session.conn.Close() // base conn would otherwise leak (and hold a p2p tunnel open)
}
delete(d.sessions, addr) // session is dead
ok = false
}
+4
View File
@@ -76,6 +76,10 @@ func (d *mwsDialer) Dial(ctx context.Context, addr string, opts ...dialer.DialOp
session, ok := d.sessions[addr]
if session != nil && session.IsClosed() {
session.Close()
if session.conn != nil {
session.conn.Close() // base conn would otherwise leak (and hold a p2p tunnel open)
}
delete(d.sessions, addr) // session is dead
ok = false
}