3x-ui/internal
Rick Sanchez fe025e8af3
feat(xray): add tunnel health monitor (#5480)
* feat(xray): add tunnel health monitor

* fix(tunnelmonitor): reuse netproxy client and init logger in tests

Replace the duplicated newHTTPClient/dialContextWithProxy with netproxy.NewHTTPClient, which centralises the http/https/socks5 handling and avoids the dial-goroutine connection leak on context cancellation. Cap failures at the threshold during cooldown so the counter stays a true consecutive-failure count. Add TestMain to initialise the logger and fix the nil-pointer panic in the success-after-failure path.

* fix(tunnelmonitor): observable recovery, signal headroom, and hardening

Address the remaining review findings on the tunnel health monitor:

- Recovery is now synchronous and observable: the callback calls
  server.RestartXray() directly and returns its error instead of just
  enqueuing SIGUSR1, so a failed restart no longer masks as success and
  arms the cooldown while the tunnel is still down.
- Give the OS signal channel headroom (buffer 8) so producers cannot
  starve a SIGTERM/SIGINT out of the single slot.
- Warn at startup when the monitor is enabled without a proxy, since the
  probe then measures host connectivity rather than the xray tunnel.
- Cap failures at the threshold in the nil-recover branch too, matching
  the cooldown cap.
- Document the XUI_TUNNEL_HEALTH_* vars in .env.example and the README.
- Add tests for status-code classification, Normalize bounds, New proxy
  scheme errors, the recovery-error and nil-recover paths, the cooldown
  cap, and Run context cancellation (coverage 90%).

---------

Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
2026-06-24 22:01:37 +02:00
..
config feat(update): add rolling dev update channel for per-commit builds 2026-06-24 18:11:22 +02:00
database feat(iplimit): gate IP limit on fail2ban and reset stale limits 2026-06-22 23:15:58 +02:00
eventbus perf: prevent cron job overlap, auto-set GOMEMLIMIT, fix tgbot userStates race 2026-06-22 02:48:58 +02:00
logger refactor(frontend): move form-item hints from extra to tooltip 2026-06-17 17:24:16 +02:00
mtproto refactor(frontend): move form-item hints from extra to tooltip 2026-06-17 17:24:16 +02:00
sub fix(sub): drive display remarks from the template and split multi-host subpage links 2026-06-24 16:45:23 +02:00
tunnelmonitor feat(xray): add tunnel health monitor (#5480) 2026-06-24 22:01:37 +02:00
util perf: prevent cron job overlap, auto-set GOMEMLIMIT, fix tgbot userStates race 2026-06-22 02:48:58 +02:00
web feat(web): vless encryption new modes (#5517) 2026-06-24 21:22:42 +02:00
xray Use efficient APIs and simplify loops 2026-06-23 14:12:28 +02:00