3x-ui/internal
冰 f0016f6cf9
test: stop swapping http.DefaultTransport in the Happ network test (#6742)
* test: stop swapping http.DefaultTransport in the Happ network test

The Happ local-generation test replaced the http.DefaultTransport global to
refuse sockets. resolvePublicIPsInBackground fires a fire-and-forget resolver
(ServerService.GetStatus -> resolvePublicIPs -> getPublicIP), and that
goroutine can outlive the test that scheduled it, so a later test writes the
global while the resolver is reading it: a data race that `make race`
(-shuffle=on) only reports when the status test happens to run first.

Route the lookup transport through an atomic swap point and count in-flight
lookups, so the test stubs its own path and waits for earlier resolvers to
settle before installing it. That also stops another test's dials from
landing in this test's zero-network tally.

Reproduced on the parent commit with -shuffle=6 (read in getPublicIP,
previous write in TestHappGenerateLocallyWithoutNetwork); the same seed is
clean with this change, across repeats and for the whole package under -race.

* test: prove the Happ network guard intercepts panel egress

The PR review pointed out that HappService.Generate never reaches a stub
installed only on the public-IP lookup, so the "zero network attempts"
assertion could not fail. Move the override onto the panel's shared egress
seam — getPublicIP and SettingService.NewProxiedHTTPClient — and gate the
test on a canary request that must be refused and must move the tally, so a
future outbound call from local generation is reported instead of passing
unnoticed.

* test(service): stop the cold-status test leaking a public-IP resolver

The race CI hit (run 37345781756) came from TestCurrentStatusSamplesBeforeFirstTick:
its CurrentStatus call starts resolvePublicIPsInBackground, a goroutine that
makes real internet requests and outlives the test. On a runner without
IPv6 every lookup waits out its 3s timeout, so the goroutine is still
building clients from http.DefaultTransport when the Happ test swaps it.

Pre-settling the IP cache keeps that test from starting the resolver at
all, so no unit test reaches the internet or leaks the goroutine. This
replaces the earlier panelEgressTransport / panelEgressLookups seam, which
added test-only hooks to production code without removing the leak.

Reproduced in golang:1.27-bookworm with egress routed to a blackhole
(HTTPS_PROXY=http://10.255.255.1:9, -race -count=3 on the two tests): the
same server.go:406 race as CI before, clean over -count=5 after.

---------

Co-authored-by: MHSanaei <ho3ein.sanaei@gmail.com>
2026-10-08 22:02:46 +02:00
..
amneziawg fix(amneziawg): bound S1-S3 by the receive buffer, reject overlapping H (#6642) 2026-09-26 22:02:49 +02:00
amneziawgnet chore(amneziawgnet): bind test sockets to loopback 2026-10-03 00:00:36 +02:00
config v3.9.0 2026-10-03 13:37:35 +02:00
crypto/nodetoken fix(nodetoken): stop refusing every node-token key file on Windows 2026-09-27 15:55:42 +02:00
database fix(database): keep the dump restore inside its own database file 2026-10-03 13:19:54 +02:00
eventbus chore: refresh dependencies, fix Linux tool tasks, modernize Go idioms 2026-07-25 16:08:09 +02:00
logger fix(logger): reuse the open log rotator when InitLogger runs again 2026-09-27 15:32:20 +02:00
mtproto fix(mtproto): synchronize child-process lifecycle (#6141) 2026-07-29 20:56:26 +02:00
nodee2e chore(nodes): run the master+node scopes in parallel and document both layers 2026-10-05 13:30:18 +02:00
pia chore(build): bump Go toolchain to 1.27.0 2026-08-23 21:57:03 +02:00
sub fix(sub): emit host TLS verification at xray level in JSON subscription 2026-10-05 22:26:04 +02:00
testpg test(database): give each package its own schema when tests run on PostgreSQL (#6594) 2026-09-26 21:13:42 +02:00
tuic fix(clients): balance renewal form layout and mode guidance (#6672) 2026-10-08 21:59:38 +02:00
tunnelmonitor
util fix(nodes): let a master's push and reconcile converge node inbounds 2026-10-05 12:17:59 +02:00
web test: stop swapping http.DefaultTransport in the Happ network test (#6742) 2026-10-08 22:02:46 +02:00
xray feat(tuic): implement native in-process Go TUIC v5 server (#6577) 2026-10-03 02:56:02 +02:00