Add nil check

This commit is contained in:
yuhan6665 2024-12-03 09:06:20 -05:00
parent 83d6acf536
commit bf47769592
2 changed files with 9 additions and 1 deletions

View File

@ -139,6 +139,10 @@ func (s *LeastLoadStrategy) selectLeastLoad(nodes []*node) []*node {
}
func (s *LeastLoadStrategy) getNodes(candidates []string, maxRTT time.Duration) []*node {
if s.observer == nil {
errors.LogError(s.ctx, "observer is nil")
return make([]*node, 0)
}
observeResult, err := s.observer.GetObservation(s.ctx)
if err != nil {
errors.LogInfoInner(s.ctx, err, "cannot get observation")

View File

@ -28,9 +28,13 @@ func (l *LeastPingStrategy) InjectContext(ctx context.Context) {
}
func (l *LeastPingStrategy) PickOutbound(strings []string) string {
if l.observatory == nil {
errors.LogError(l.ctx, "observer is nil")
return ""
}
observeReport, err := l.observatory.GetObservation(l.ctx)
if err != nil {
errors.LogInfoInner(l.ctx, err, "cannot get observe report")
errors.LogInfoInner(l.ctx, err, "cannot get observer report")
return ""
}
outboundsList := outboundList(strings)