From 0d83d099ac1bcf696a5a37bee7e1a84aa7f00369 Mon Sep 17 00:00:00 2001 From: Fangliding Date: Thu, 8 Oct 2026 19:03:48 +0800 Subject: [PATCH] make client unavailable if instance stopped --- transport/internet/hysteria/config.go | 1 + transport/internet/hysteria/dialer.go | 18 +++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/transport/internet/hysteria/config.go b/transport/internet/hysteria/config.go index bf87d604c..24d4a98be 100644 --- a/transport/internet/hysteria/config.go +++ b/transport/internet/hysteria/config.go @@ -79,6 +79,7 @@ const ( StatusNull status = iota StatusActive StatusInactive + StatusClosed ) const protocolName = "hysteria" diff --git a/transport/internet/hysteria/dialer.go b/transport/internet/hysteria/dialer.go index bfd92eabd..dedc02fd6 100644 --- a/transport/internet/hysteria/dialer.go +++ b/transport/internet/hysteria/dialer.go @@ -44,6 +44,9 @@ type client struct { } func (c *client) status() status { + if c.instance != nil && !c.instance.IsRunning() { + return StatusClosed + } if c.conn == nil { return StatusNull } @@ -68,11 +71,12 @@ func (c *client) close() { } func (c *client) dial(ctx context.Context) error { - status := c.status() - if status == StatusActive { + switch c.status() { + case StatusClosed: + return errors.New("client is closed") + case StatusActive: return nil - } - if status == StatusInactive { + case StatusInactive: c.close() } @@ -263,11 +267,11 @@ func (c *client) udp(ctx context.Context) (stat.Connection, error) { func (c *client) clean() (shouldDelete bool) { c.Lock() defer c.Unlock() - if c.instance != nil && !c.instance.IsRunning() { + switch c.status() { + case StatusClosed: c.close() return true - } - if c.status() == StatusInactive { + case StatusInactive: c.close() return false }