From e1bc43da5f1f06ea00bd28923b37b5d029522359 Mon Sep 17 00:00:00 2001 From: yeer Date: Tue, 23 Jul 2024 17:11:28 +0800 Subject: [PATCH] fix bug for nil pointer (#2438) --- xray/api.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xray/api.go b/xray/api.go index d7d916d3..d0de76e8 100644 --- a/xray/api.go +++ b/xray/api.go @@ -181,6 +181,10 @@ func (x *XrayAPI) GetTraffic(reset bool) ([]*Traffic, []*ClientTraffic, error) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) defer cancel() + if x.StatsServiceClient == nil { + return nil, nil, common.NewError("xray StatusServiceClient is not initialized") + } + resp, err := (*x.StatsServiceClient).QueryStats(ctx, &statsService.QueryStatsRequest{Reset_: reset}) if err != nil { logger.Debug("Failed to query Xray stats:", err)