Skip to content

Commit 4976b52

Browse files
committed
fix: standardize xray observatory read timeout in GetOutboundsLatency
1 parent e4e1946 commit 4976b52

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

backend/xray/latency.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,19 @@ type debugVarsResponse struct {
2525
Observatory map[string]observatoryEntry `json:"observatory"`
2626
}
2727

28+
const xrayObservatoryReadTimeout = 5 * time.Second
29+
2830
func (x *Xray) GetOutboundsLatency(ctx context.Context, request *common.LatencyRequest) (*common.LatencyResponse, error) {
2931
x.mu.RLock()
3032
started := x.core != nil && x.core.Started()
3133
metricPort := x.metricPort
32-
timeoutSeconds := x.cfg.LatencyTimeoutSeconds
3334
x.mu.RUnlock()
3435

3536
if !started {
3637
return nil, errors.New("xray not started")
3738
}
3839

39-
client := &http.Client{Timeout: time.Duration(timeoutSeconds) * time.Second}
40+
client := &http.Client{Timeout: xrayObservatoryReadTimeout}
4041
addr := netip.AddrPortFrom(netip.MustParseAddr("127.0.0.1"), uint16(metricPort))
4142
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://"+addr.String()+"/debug/vars", nil)
4243
if err != nil {

backend/xray/xray_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,11 @@ func TestGetOutboundsLatencyWithRealXray(t *testing.T) {
174174
}
175175

176176
cfg := &config.Config{
177-
XrayExecutablePath: executablePath,
178-
XrayAssetsPath: assetsPath,
179-
GeneratedConfigPath: configPath,
180-
Debug: false,
181-
LogBufferSize: 1000,
182-
LatencyTimeoutSeconds: 5,
177+
XrayExecutablePath: executablePath,
178+
XrayAssetsPath: assetsPath,
179+
GeneratedConfigPath: configPath,
180+
Debug: false,
181+
LogBufferSize: 1000,
183182
}
184183

185184
back, err := New(

0 commit comments

Comments
 (0)