mirror of
https://github.com/go-gost/x.git
synced 2026-10-19 16:16:32 +00:00
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:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user