Repository navigation
Metrics: Close HTTP connections when stopping Xray Instance - #7361
Merged
Merged
Conversation
Retain the HTTP server serving both metrics listeners and close its accepted connections together with the core, so persistent collectors cannot keep using a stopped instance after an embedded application restarts it. Cover direct, tagged and combined listeners with keep-alive regressions. Assisted-by: Codex Signed-off-by: Eljees <[email protected]>
Instance
patterniha
added a commit
to patterniha/Xray-core
that referenced
this pull request
Nov 12, 2026
Brings in XTLS/Xray-core up to c456141 (still v26.11.9): - Build: build list optimization and build-tag clean-up (XTLS#5824) - Hysteria transport: proper Brutal behavior; bump quic-go to v0.63.1-...a10df75c (XTLS#7356) - Metrics: close HTTP connections when stopping the Instance (XTLS#7361) - XDNS finalmask: TCP resolver worker (XTLS#7354) - VLESS mux.cool: maxConcurrency 128 only for XDRIVE (XTLS#7375); replace MutexWriter with buf.BufferedWriter (XTLS#7359) No conflicts: upstream and the fork changed disjoint files; go.mod/go.sum are taken from upstream unchanged. The fork's core/core.go version (26.11.12) is kept.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When an application embeds Xray and restarts an
Instance, an HTTP collector can keep using its existing metrics keep-alive connection afterInstance.Close(). The old handler remains available instead of the collector reconnecting to the new instance. This affects both directmetrics.listenand connections routed tometrics.tag.http.Servecreates an HTTP server that the metrics handler does not retain. Closing its listeners stops new accepts, but leaves accepted connections open. Retain onehttp.Serverfor both listeners and close it with the metrics handler, while keeping the existing explicit listener cleanup. Capture the server before starting either serving goroutine so an immediate close is also handled.The regression starts actual core instances, makes a successful HTTP/1.1 request, calls
Instance.Close, then checks that the same connection can no longer receive any HTTP response. It coverslisten,tag, and both together; all three fail against the original production code. Fixtures use only a loopback listener and in-memory connections.Related: #6349, which supports restarting metrics-enabled instances in the same process.
Validation:
./app/metrics ./app/statspass; scopedgo vetand main build pass.-race; scopedgo vetand main build pass.Implemented and tested with Codex assistance.