Browse Source

fix bug for nil pointer (#2438)

yeer 3 months ago
parent
commit
e1bc43da5f
1 changed files with 4 additions and 0 deletions
  1. 4 0
      xray/api.go

+ 4 - 0
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)
 	ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
 	defer cancel()
 	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})
 	resp, err := (*x.StatsServiceClient).QueryStats(ctx, &statsService.QueryStatsRequest{Reset_: reset})
 	if err != nil {
 	if err != nil {
 		logger.Debug("Failed to query Xray stats:", err)
 		logger.Debug("Failed to query Xray stats:", err)