[PR #6577] [MERGED] feat(tuic): implement native in-process Go TUIC v5 server #6357

Closed
opened 2026-11-02 04:08:12 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6577
Author: @poise52
Created: 9/16/2026
Status: ✅ Merged
Merged: 10/3/2026
Merged by: @MHSanaei

Base: main ← Head: feat/tuic-native-go


📝 Commits (10+)

  • 5fdefa5 feat(tuic): implement native in-process Go TUIC v5 server
  • b194c4c Merge branch 'main' into feat/tuic-native-go
  • e4e58c0 Merge branch 'MHSanaei:main' into feat/tuic-native-go
  • b272bee fix(tuic): address traffic accounting, client reload, and socket lifecycle issues
  • a73737a Merge branch 'MHSanaei:main' into feat/tuic-native-go
  • 520634d fix(service): update checkTuicSocksReverseConflict to use bindAddr for listenOverlaps
  • 846fd6b fix(tuic): resolve traffic double-accounting, UDP fragmentation, and socket lifecycle issues
  • 386deb3 feat(tuic): complete native Go integration and address audit findings
  • e960dc0 Merge main into feat/tuic-native-go and preserve TUIC Host compatibility
  • f0d4360 Merge main into feat/tuic-native-go

📊 Changes

100 files changed (+7930 additions, -1455 deletions)

View changed files

📝 .github/workflows/release.yml (+0 -25)
📝 DockerInit.sh (+0 -21)
📝 docs/architecture.md (+6 -7)
📝 docs/content/docs/en/config/clients.mdx (+1 -1)
📝 docs/content/docs/en/config/inbounds.mdx (+1 -1)
📝 docs/content/docs/en/config/tuic.mdx (+8 -11)
📝 docs/content/docs/fa/config/clients.mdx (+1 -1)
📝 docs/content/docs/fa/config/inbounds.mdx (+1 -1)
📝 docs/content/docs/ru/config/clients.mdx (+1 -1)
📝 docs/content/docs/ru/config/inbounds.mdx (+1 -1)
📝 docs/content/docs/ru/config/tuic.mdx (+8 -11)
📝 docs/content/docs/zh/config/clients.mdx (+1 -1)
📝 docs/content/docs/zh/config/inbounds.mdx (+1 -1)
➕ frontend/src/lib/tuic.ts (+35 -0)
📝 frontend/src/lib/xray/inbound-form-adapter.ts (+7 -1)
📝 frontend/src/lib/xray/inbound-link.ts (+5 -3)
📝 frontend/src/pages/clients/ClientBulkAddModal.tsx (+1 -16)
📝 frontend/src/pages/clients/ClientFormModal.tsx (+1 -18)
📝 frontend/src/pages/clients/tuicConfig.ts (+2 -1)
📝 frontend/src/pages/inbounds/form/protocols/tuic.tsx (+19 -29)

...and 80 more files

📄 Description

Summary

Replaces the external Rust tuic-server sidecar with a native in-process Go TUIC v5 server built on github.com/apernet/quic-go, the QUIC stack xray-core already ships. Decrypted TCP and UDP traffic goes through a loopback SOCKS5 inbound into Xray-core, so TUIC traffic follows Xray routing like any other inbound.

Fixes #6560

Why

  1. Xray routing and cascading: the sidecar bypassed Xray completely. Traffic now enters a loopback SOCKS5 inbound tagged with the TUIC inbound's own tag, so geosite/geoip/domain rules and cascading outbounds (WARP, VLESS, Shadowsocks…) apply.
  2. Per-client quota and expiry: bytes are metered per client natively, so totalGB, expiryTime and "start after first use" are enforced per client, not just per inbound. Online status no longer depends on parsing sidecar log lines.
  3. Hot client updates: adding, editing or disabling a client updates the in-memory user registry. The listener keeps running and other clients' sessions are not dropped. The sidecar restarted on every client change.
  4. No external binary: tuic-server is no longer downloaded in install.sh, update.sh, DockerInit.sh or release.yml. Old sidecar processes and files are cleaned up on install/update.

Benchmark (main sidecar vs this PR)

Same TUIC client for both, loopback, default bbr, Linux (Docker). This PR's path includes the hop through real Xray.

main (sidecar) this PR
TCP, 1 stream 780 Mbit/s 3383 Mbit/s
TCP, 8 streams 836 Mbit/s 3555 Mbit/s
UDP datagram RTT p50 705 µs 619 µs
Live connection when a client is edited dropped, ~3 s downtime kept

A CONNECT whose first payload is neither TLS nor HTTP waits ~200 ms for Xray sniffing, which is the same as every other sniffing-enabled Xray inbound. TLS traffic is not affected.

Notes for operators

  • Congestion control: bbr (default) and new_reno run server-side. cubic is still written to client profiles, but the server serves it as new_reno because quic-go has no CUBIC sender.
  • TUIC now depends on Xray: an Xray restart interrupts TUIC upstream flows. Adding, removing, enabling or disabling a TUIC inbound restarts Xray to (re)create its relay inbound, the same as AmneziaWG. Client edits do not.
  • Each TUIC inbound reserves a loopback relay port in 64001–65000, derived from its id. Port conflicts with it are checked on save.

Maintainer fixes on top of the contribution

  • Merged main (node deployment of AmneziaWG/TUIC/MTProto): the forwarded-ports check stays node-scoped, and the TUIC relay port is checked next to AmneziaWG's.
  • Removed the github.com/poise52/quic-go fork. BBR is installed per connection with xray-core's congestion.UseBBR on apernet/quic-go, which removed a second QUIC/TLS stack and the cross-module BBR adapter.
  • The duplicate-UUID check query had no subquery alias, which PostgreSQL < 16 rejects. Every client sync, for every protocol, failed on PostgreSQL 14/15 until this was fixed (reproduced on postgres:15).
  • tuic_traffic_receipts was created by a runtime CREATE TABLE. It is now a GORM model registered in allModels and migrationModels, so x-ui migrate-db carries it.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

  • make test-go, make lint (0 issues), make gen-check, and frontend tests (179 files / 1786 tests), build and build-storybook.
  • internal/tuic full suite and -race on Linux: green.
  • TestSyncInboundClientsOnPostgres against PostgreSQL 15: red before the alias fix, green after.
  • Benchmark above, against the real tuic-server 1.0.0 sidecar from main and a real Xray build.
  • Not covered: Xray gRPC e2e tests, and throughput over a real network or on ARM.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6577 **Author:** [@poise52](https://github.com/poise52) **Created:** 9/16/2026 **Status:** ✅ Merged **Merged:** 10/3/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `feat/tuic-native-go` --- ### 📝 Commits (10+) - [`5fdefa5`](https://github.com/MHSanaei/3x-ui/commit/5fdefa5a5f1ef5ef0e6d7fd7bca19fca6f16eb55) feat(tuic): implement native in-process Go TUIC v5 server - [`b194c4c`](https://github.com/MHSanaei/3x-ui/commit/b194c4cb26bedf39959c6cffc22ed719de376d4d) Merge branch 'main' into feat/tuic-native-go - [`e4e58c0`](https://github.com/MHSanaei/3x-ui/commit/e4e58c0db4af0bc54bb30e6a6312ba0735cd3332) Merge branch 'MHSanaei:main' into feat/tuic-native-go - [`b272bee`](https://github.com/MHSanaei/3x-ui/commit/b272bee1a85e7509104fb67981de9856931ad30f) fix(tuic): address traffic accounting, client reload, and socket lifecycle issues - [`a73737a`](https://github.com/MHSanaei/3x-ui/commit/a73737a865eadd67a57c6e0bf304c830377440eb) Merge branch 'MHSanaei:main' into feat/tuic-native-go - [`520634d`](https://github.com/MHSanaei/3x-ui/commit/520634d36869fdb7241197e8240a4abb2fb46b59) fix(service): update checkTuicSocksReverseConflict to use bindAddr for listenOverlaps - [`846fd6b`](https://github.com/MHSanaei/3x-ui/commit/846fd6b885d7e7db716d03e28e2eb3b63f7c4758) fix(tuic): resolve traffic double-accounting, UDP fragmentation, and socket lifecycle issues - [`386deb3`](https://github.com/MHSanaei/3x-ui/commit/386deb323b6398791b2fce96f15025a516f46eda) feat(tuic): complete native Go integration and address audit findings - [`e960dc0`](https://github.com/MHSanaei/3x-ui/commit/e960dc014b640661a129b890b684b73d539195bd) Merge main into feat/tuic-native-go and preserve TUIC Host compatibility - [`f0d4360`](https://github.com/MHSanaei/3x-ui/commit/f0d436048ef3a8759da5ce4a59c7893c2b8e5792) Merge main into feat/tuic-native-go ### 📊 Changes **100 files changed** (+7930 additions, -1455 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/release.yml` (+0 -25) 📝 `DockerInit.sh` (+0 -21) 📝 `docs/architecture.md` (+6 -7) 📝 `docs/content/docs/en/config/clients.mdx` (+1 -1) 📝 `docs/content/docs/en/config/inbounds.mdx` (+1 -1) 📝 `docs/content/docs/en/config/tuic.mdx` (+8 -11) 📝 `docs/content/docs/fa/config/clients.mdx` (+1 -1) 📝 `docs/content/docs/fa/config/inbounds.mdx` (+1 -1) 📝 `docs/content/docs/ru/config/clients.mdx` (+1 -1) 📝 `docs/content/docs/ru/config/inbounds.mdx` (+1 -1) 📝 `docs/content/docs/ru/config/tuic.mdx` (+8 -11) 📝 `docs/content/docs/zh/config/clients.mdx` (+1 -1) 📝 `docs/content/docs/zh/config/inbounds.mdx` (+1 -1) ➕ `frontend/src/lib/tuic.ts` (+35 -0) 📝 `frontend/src/lib/xray/inbound-form-adapter.ts` (+7 -1) 📝 `frontend/src/lib/xray/inbound-link.ts` (+5 -3) 📝 `frontend/src/pages/clients/ClientBulkAddModal.tsx` (+1 -16) 📝 `frontend/src/pages/clients/ClientFormModal.tsx` (+1 -18) 📝 `frontend/src/pages/clients/tuicConfig.ts` (+2 -1) 📝 `frontend/src/pages/inbounds/form/protocols/tuic.tsx` (+19 -29) _...and 80 more files_ </details> ### 📄 Description ## Summary Replaces the external Rust `tuic-server` sidecar with a native in-process Go TUIC v5 server built on `github.com/apernet/quic-go`, the QUIC stack xray-core already ships. Decrypted TCP and UDP traffic goes through a loopback SOCKS5 inbound into Xray-core, so TUIC traffic follows Xray routing like any other inbound. Fixes #6560 ## Why 1. **Xray routing and cascading**: the sidecar bypassed Xray completely. Traffic now enters a loopback SOCKS5 inbound tagged with the TUIC inbound's own tag, so geosite/geoip/domain rules and cascading outbounds (WARP, VLESS, Shadowsocks…) apply. 2. **Per-client quota and expiry**: bytes are metered per client natively, so `totalGB`, `expiryTime` and "start after first use" are enforced per client, not just per inbound. Online status no longer depends on parsing sidecar log lines. 3. **Hot client updates**: adding, editing or disabling a client updates the in-memory user registry. The listener keeps running and other clients' sessions are not dropped. The sidecar restarted on every client change. 4. **No external binary**: `tuic-server` is no longer downloaded in `install.sh`, `update.sh`, `DockerInit.sh` or `release.yml`. Old sidecar processes and files are cleaned up on install/update. ## Benchmark (main sidecar vs this PR) Same TUIC client for both, loopback, default `bbr`, Linux (Docker). This PR's path includes the hop through real Xray. | | main (sidecar) | this PR | |---|---|---| | TCP, 1 stream | 780 Mbit/s | **3383 Mbit/s** | | TCP, 8 streams | 836 Mbit/s | **3555 Mbit/s** | | UDP datagram RTT p50 | 705 µs | 619 µs | | Live connection when a client is edited | dropped, ~3 s downtime | **kept** | A CONNECT whose first payload is neither TLS nor HTTP waits ~200 ms for Xray sniffing, which is the same as every other sniffing-enabled Xray inbound. TLS traffic is not affected. ## Notes for operators - Congestion control: `bbr` (default) and `new_reno` run server-side. `cubic` is still written to client profiles, but the server serves it as `new_reno` because quic-go has no CUBIC sender. - TUIC now depends on Xray: an Xray restart interrupts TUIC upstream flows. Adding, removing, enabling or disabling a TUIC inbound restarts Xray to (re)create its relay inbound, the same as AmneziaWG. Client edits do not. - Each TUIC inbound reserves a loopback relay port in `64001–65000`, derived from its id. Port conflicts with it are checked on save. ## Maintainer fixes on top of the contribution - Merged `main` (node deployment of AmneziaWG/TUIC/MTProto): the forwarded-ports check stays node-scoped, and the TUIC relay port is checked next to AmneziaWG's. - Removed the `github.com/poise52/quic-go` fork. BBR is installed per connection with xray-core's `congestion.UseBBR` on `apernet/quic-go`, which removed a second QUIC/TLS stack and the cross-module BBR adapter. - The duplicate-UUID check query had no subquery alias, which PostgreSQL < 16 rejects. Every client sync, for every protocol, failed on PostgreSQL 14/15 until this was fixed (reproduced on `postgres:15`). - `tuic_traffic_receipts` was created by a runtime `CREATE TABLE`. It is now a GORM model registered in `allModels` and `migrationModels`, so `x-ui migrate-db` carries it. ## Type of change - [ ] Bug fix - [x] New feature - [x] Refactoring (no behavior change) - [x] Documentation - [ ] Tests only - [x] Build / CI / tooling - [ ] Other ## Areas affected - [x] Frontend (UI / panel pages) - [x] Backend (API endpoints, login, settings) - [x] Xray config generation - [x] Subscription (share links / Clash / JSON) - [x] Statistics / traffic counters - [x] Database / migrations - [x] Install / upgrade script - [x] Docker image - [x] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? - `make test-go`, `make lint` (0 issues), `make gen-check`, and frontend tests (179 files / 1786 tests), `build` and `build-storybook`. - `internal/tuic` full suite and `-race` on Linux: green. - `TestSyncInboundClientsOnPostgres` against PostgreSQL 15: red before the alias fix, green after. - Benchmark above, against the real `tuic-server` 1.0.0 sidecar from `main` and a real Xray build. - Not covered: Xray gRPC e2e tests, and throughput over a real network or on ARM. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [x] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [x] I updated the Wiki / README / API docs if user-facing behavior changed. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:08:12 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6357
No description provided.