make client unavailable if instance stopped

This commit is contained in:
Fangliding
2026-10-08 19:03:48 +08:00
parent d06cf79243
commit 0d83d099ac
2 changed files with 12 additions and 7 deletions
+1
View File
@@ -79,6 +79,7 @@ const (
StatusNull status = iota
StatusActive
StatusInactive
StatusClosed
)
const protocolName = "hysteria"
+11 -7
View File
@@ -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
}