Hysteria: Remove closed instance conn

This commit is contained in:
Fangliding
2026-10-08 15:35:39 +08:00
parent 0086362663
commit d06cf79243
2 changed files with 42 additions and 19 deletions
+6 -5
View File
@@ -4,6 +4,7 @@ import (
"context"
"reflect"
"sync"
"sync/atomic"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/errors"
@@ -84,7 +85,7 @@ type Instance struct {
features []features.Feature
pendingResolutions []resolution
pendingOptionalResolutions []resolution
running bool
running atomic.Bool
resolveLock sync.Mutex
ctx context.Context
@@ -92,7 +93,7 @@ type Instance struct {
// Instance state
func (server *Instance) IsRunning() bool {
return server.running
return server.running.Load()
}
func AddInboundHandler(server *Instance, config *InboundHandlerConfig) error {
@@ -262,7 +263,7 @@ func (s *Instance) Close() error {
s.statusLock.Lock()
defer s.statusLock.Unlock()
s.running = false
s.running.Store(false)
var errs []interface{}
for _, f := range s.features {
@@ -320,7 +321,7 @@ func (s *Instance) RequireFeatures(callback interface{}, optional bool) error {
// AddFeature registers a feature into current Instance.
func (s *Instance) AddFeature(feature features.Feature) error {
if s.running {
if s.running.Load() {
if err := feature.Start(); err != nil {
errors.LogInfoInner(s.ctx, err, "failed to start feature")
}
@@ -388,7 +389,7 @@ func (s *Instance) Start() error {
s.statusLock.Lock()
defer s.statusLock.Unlock()
s.running = true
s.running.Store(true)
for _, f := range s.features {
if err := f.Start(); err != nil {
return err