From 7c240e8630815d2954a3ffac7860f0e06011de11 Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Sat, 13 Nov 2021 23:23:38 -0500 Subject: [PATCH] Fix null pointer exception for observatory Core setup router object first, when InjectContext() is called, observatory object is still null, so observatory need to be injected after InjectContext() --- app/router/strategy_leastping.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/router/strategy_leastping.go b/app/router/strategy_leastping.go index ddb5116a..2b9e2789 100644 --- a/app/router/strategy_leastping.go +++ b/app/router/strategy_leastping.go @@ -15,14 +15,17 @@ type LeastPingStrategy struct { } func (l *LeastPingStrategy) InjectContext(ctx context.Context) { - common.Must(core.RequireFeatures(ctx, func(observatory extension.Observatory) error { - l.observatory = observatory - return nil - })) l.ctx = ctx } func (l *LeastPingStrategy) PickOutbound(strings []string) string { + if l.observatory == nil { + common.Must(core.RequireFeatures(l.ctx, func(observatory extension.Observatory) error { + l.observatory = observatory + return nil + })) + } + observeReport, err := l.observatory.GetObservation(l.ctx) if err != nil { newError("cannot get observe report").Base(err).WriteToLog()