mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-10-09 09:10:11 +00:00
Hysteria: Remove closed instance conn
This commit is contained in:
+6
-5
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user