mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-06-14 23:38:40 +00:00
Core: Fix memory leaks with RequireFeatures() (#4095)
Fixes https://github.com/XTLS/Xray-core/issues/4054 Fixes https://github.com/XTLS/Xray-core/issues/3338 Fixes https://github.com/XTLS/Xray-core/issues/3221
This commit is contained in:
parent
a2b773135a
commit
0e2304c403
15 changed files with 98 additions and 59 deletions
|
@ -7,7 +7,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/xtls/xray-core/app/observatory"
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/dice"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/core"
|
||||
|
@ -58,8 +57,11 @@ type node struct {
|
|||
RTTDeviationCost time.Duration
|
||||
}
|
||||
|
||||
func (l *LeastLoadStrategy) InjectContext(ctx context.Context) {
|
||||
l.ctx = ctx
|
||||
func (s *LeastLoadStrategy) InjectContext(ctx context.Context) {
|
||||
s.ctx = ctx
|
||||
core.RequireFeaturesAsync(s.ctx, func(observatory extension.Observatory) {
|
||||
s.observer = observatory
|
||||
})
|
||||
}
|
||||
|
||||
func (s *LeastLoadStrategy) PickOutbound(candidates []string) string {
|
||||
|
@ -136,10 +138,8 @@ func (s *LeastLoadStrategy) selectLeastLoad(nodes []*node) []*node {
|
|||
|
||||
func (s *LeastLoadStrategy) getNodes(candidates []string, maxRTT time.Duration) []*node {
|
||||
if s.observer == nil {
|
||||
common.Must(core.RequireFeatures(s.ctx, func(observatory extension.Observatory) error {
|
||||
s.observer = observatory
|
||||
return nil
|
||||
}))
|
||||
errors.LogError(s.ctx, "observer is nil")
|
||||
return make([]*node, 0)
|
||||
}
|
||||
observeResult, err := s.observer.GetObservation(s.ctx)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue