mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6742] [MERGED] test: stop swapping http.DefaultTransport in the Happ network test #6437
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6437
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6742
Author: @AyaseEli-Bing
Created: 10/5/2026
Status: ✅ Merged
Merged: 10/8/2026
Merged by: @MHSanaei
Base:
main← Head:fix/race-public-ip-lookup-transport📝 Commits (6)
249a3b8test: stop swapping http.DefaultTransport in the Happ network test735f283test: prove the Happ network guard intercepts panel egress6b6b917Merge branch 'main' into fix/race-public-ip-lookup-transport45a3ffetest(service): stop the cold-status test leaking a public-IP resolver147d4f1Merge remote-tracking branch 'origin/main' into pr-6742ecfbda2Merge branch 'main' into fix/race-public-ip-lookup-transport📊 Changes
1 file changed (+3 additions, -1 deletions)
View changed files
📝
internal/web/service/server_cold_status_test.go(+3 -1)📄 Description
Related issue
None filed — I checked first: no open issue mentions
TestHappGenerateLocallyWithoutNetwork, and no open issue reports theracejob flaking. Happy to file one if you would rather track it separately.What changed
internal/web/service/happ_local_test.gono longer assignshttp.DefaultTransport. The panel's own ad-hoc HTTP clients are now built through one swap point (internal/web/service/server.go:panelEgressTransport+panelEgressLookups, withpanelEgressClient/applyPanelEgressTransport), which the test stubs atomically, waits to drain, and proves is live before asserting on it.Why
ServerService.GetStatusstartsresolvePublicIPsInBackground(server.go:507), a fire-and-forget goroutine that ends up ingetPublicIPbuilding&http.Client{Timeout: 3s}with a nilTransport— i.e. it reads thehttp.DefaultTransportvariable at request time.TestHappGenerateLocallyWithoutNetworkwrote that same global to refuse sockets. Tests run sequentially inside a package, but the resolver goroutine does not: it outlives the test that scheduled it, so a later test writes the global while that goroutine is reading it.That is the race CI reported on
mainafter #6740 (run37345781756, jobrace, 26 reports, every stack insideinternal/web/service/net/http). It only surfaces when-shuffle=onhappens to schedule a status-sampling test before the Happ one — which is why the three pushes before mine were green and this one was not. Nothing in #6740 is involved:internal/subappears in none of the stacks.The secondary effect is worth fixing in the same stroke: a leaked resolver that dials through the swapped transport also bumps the test's own
callscounter, so the "zero network attempts" assertion was measuring other tests' traffic. Draining before installing the stub makes the tally mean what its name says.Review follow-up (
735f283)The review correctly pointed out that stubbing only the public-IP lookup left the assertion vacuous:
HappService.Generatenever reaches that code, so the tally could not move, and a future outbound call from local generation would pass unnoticed. Two changes address it:SettingService.NewProxiedHTTPClient— the helper the panel itself uses for its own egress (subscription fetches, warp, sponsor, Telegram) — now routes through the same swap point, so code added to generation later meets the override at the door rather than silently bypassing it.Generate, the test sends one request through the seam and requires both an error and that the dial tally moved.panel-egress-canary.invalidis reserved by RFC 6761, so the error alone proves nothing; the tally check is what turns a dead stub into a loud failure.Negative control, run on purpose by disabling the
Load()branch inpanelEgressClient:Verification
On this branch:
ok 6.5s; the whole package under-shuffle=6→ok 80.5s, and under-shuffle=on→ok 64.1s; 0 races.golangci-lint run internal/web/service/...→0 issues.gofmt -l internal/web/service/→ emptygo vet ./internal/web/service/ ./internal/util/netproxy/→ cleanNot run here:
make node-e2e, the live-Postgres job,make vulncheck, and the frontend targets (no frontend file touched). CI is the real gate for those.Impact
No behaviour change in production:
panelEgressTransportis nil unless a test sets it, sopanelEgressClientkeepsTransport == niland thehttp.Clientdefault applies exactly as before, andapplyPanelEgressTransportleaves clients that already carry a transport (a configured proxy) untouched. The added cost is two atomic operations per public-IP lookup, which runs at most once per address family perServerService.AI assistance
This patch was produced by an AI coding agent (Qoder) at the request of the account owner, who reviewed the diff and the reproduction above. Same author as #6740.
Checklist
waitForPanelEgressLookupsfatal) if a resolver never settles, and fails loudly (canary) if the stub is not intercepting.go build ./...and the test suite pass locally.internal/web/service.)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.