[PR #6526] [MERGED] fix(outbound): read the probe protocol id and transport name like the core #6332

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6526
Author: @BlindMaster24
Created: 9/14/2026
Status: ✅ Merged
Merged: 9/14/2026
Merged by: @BlindMaster24

Base: main ← Head: fix/outbound-probe-protocol-case


📝 Commits (2)

  • f7907aa fix(outbound): read the probe protocol id and transport name like the core
  • a82476c fix(outbound): read the batch probe protocol id like the core

📊 Changes

3 files changed (+161 additions, -4 deletions)

View changed files

📝 internal/web/service/outbound/outbound.go (+16 -2)
📝 internal/web/service/outbound/probe_http.go (+2 -2)
➕ internal/web/service/outbound/probe_protocol_case_test.go (+143 -0)

📄 Description

Summary

The outbound probe decides between its dial-only TCP lane and the real xray handshake probe by reading the protocol id and the stream transport name. Both readers compared those strings exactly, so a template the core is running was probed as if it were a different protocol.

Follow-up to a review finding on #6525, where the same reader was fixed in the browser.

Why

The core normalises both names before it resolves them — infra/conf/loader.go lowercases the protocol id, and TransportProtocol.Build (infra/conf/transport_internet.go:16-17) lowercases the transport name and additionally resolves both "kcp" and "mkcp" to mKCP.

Scenario. An operator's config spells an outbound "WireGuard" — pasted, or hand-edited, or written by another tool — and the core runs it without a word. Someone calls POST /panel/api/xray/testOutbound with mode=tcp (or testOutbounds), as the panel itself did before #6525 and as a script polling the API still does. Then:

  1. outboundTransportIsUDP compares "WireGuard" against "wireguard", gets false, and keeps the outbound in the dial-only TCP lane — the lane it exists to keep UDP transports out of, because a bare dial neither proves reachability nor measures latency for a protocol that ignores unauthenticated packets.
  2. extractOutboundEndpoints switches on the raw protocol string, matches no case, and returns nothing.
  3. The caller gets No testable endpoint for an outbound that is passing traffic right now.

The transport-name half has the same shape and an extra edge: "network": "mkcp" is a spelling the core accepts and builds mKCP from, and it was not recognised at all. The endpoint's own documented contract (frontend/src/pages/api-docs/endpoints.ts) states that mode=tcp gives fast dial-only probes with UDP-transport outbounds still probed over HTTP — the first step above is where that promise was broken.

What changed

  • outboundTransportIsUDP matches the proxy protocols and the transport names case-insensitively, and recognises the mkcp alias.
  • extractOutboundEndpoints lowercases the protocol id before its switch.

Not changed, deliberately — and one correction to what this description first claimed. The literal comparisons at probe_http.go:184-188 (the blackhole / loopback / freedom / dns rejections) are still exact in this PR, and this diff stays backend-only. An earlier version of this paragraph said the panel never reaches them with a different spelling, because the frontend skips those outbounds before the request leaves the browser. That is wrong, and this PR's own review disproved it. isUntestable (frontend/src/pages/xray/outbounds/outbounds-tab-helpers.ts:57) is the only gate on the row's Test button and it compares the id exactly as well, so a "Freedom" outbound is probed through the direct outbound and the API answers success: true with the panel host's own country and delay — the operator reads the panel's own reachability as a working tunnel. That is a separate, pre-existing bug, fixed in #6527 rather than here. The blackhole/freedom check in testOutboundTCP (outbound.go:160) stays exact too: it is message precision only, since extractOutboundEndpoints finds no endpoint for those ids either way.

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 (the outbound test/probe path)
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

Three new tests in internal/web/service/outbound/, all confirmed red before the fix and green after:

  • TestTestOutboundsTCPModeForcesCoreSpelledUDPToHTTPProbe drives the real TestOutbounds(..., "tcp") through a stub xray process and asserts the result comes back from the HTTP probe. Before: Success:false Error:"No testable endpoint" Mode:"tcp".
  • TestOutboundTransportIsUDPMatchesTheCore is a table over both readers' spellings — WireGuard, HYSTERIA, KCP, mkcp, MKCP must be UDP; tcp, ws and a plain vless must not. Five substests fail before the fix.
  • TestTestOutboundsTCPLaneReadsProtocolIDCaseInsensitively puts a "SOCKS" outbound in the TCP lane against a real local listener, so it fails on the extractor alone rather than through the lane gate.

Local verification, and one honest caveat about how. This machine has no C compiler, and internal/database is a dependency of the package, so it does not build with CGO_ENABLED=0 on its own — internal/database/db.go:2812 calls the cgo-only sqlite3.SQLiteConn.Backup. I verified with go test -overlay pointing at a copy of db.go in which that one call is replaced by an error return; no file this PR changes is substituted, only that single cgo call. Under that rig: go test ./internal/web/service/outbound/ passes in full (the pre-existing suite included), gofmt -l is clean and go vet is clean. Real-CGo compilation, race, the Postgres job and the build matrix are left to CI.

Screenshots / recordings

N/A — backend only.

Breaking changes

None. Canonical spellings behave exactly as before; only templates the core already accepts and the probe previously misread change behaviour, and they change from a wrong answer to the right one.

Checklist

  • I tested the change locally and confirmed the described behavior. — Confirmed for the package under the overlay rig described above; go build ./... itself needs CGo on this machine.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally. — Blocked by the missing C compiler here; CI covers it.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass. — No frontend file is touched.
  • I updated the Wiki / README / API docs if user-facing behavior changed. — No endpoint, request shape or response field changed; only which lane a request lands in.
  • 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/6526 **Author:** [@BlindMaster24](https://github.com/BlindMaster24) **Created:** 9/14/2026 **Status:** ✅ Merged **Merged:** 9/14/2026 **Merged by:** [@BlindMaster24](https://github.com/BlindMaster24) **Base:** `main` ← **Head:** `fix/outbound-probe-protocol-case` --- ### 📝 Commits (2) - [`f7907aa`](https://github.com/MHSanaei/3x-ui/commit/f7907aad431e5e9bd58eff1b6fafc014cef7638a) fix(outbound): read the probe protocol id and transport name like the core - [`a82476c`](https://github.com/MHSanaei/3x-ui/commit/a82476c9d0b79ce3ad4d5ca644a9a968fc8ecbc4) fix(outbound): read the batch probe protocol id like the core ### 📊 Changes **3 files changed** (+161 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/service/outbound/outbound.go` (+16 -2) 📝 `internal/web/service/outbound/probe_http.go` (+2 -2) ➕ `internal/web/service/outbound/probe_protocol_case_test.go` (+143 -0) </details> ### 📄 Description ## Summary The outbound probe decides between its dial-only TCP lane and the real xray handshake probe by reading the protocol id and the stream transport name. Both readers compared those strings exactly, so a template the core is running was probed as if it were a different protocol. Follow-up to a review finding on #6525, where the same reader was fixed in the browser. ## Why The core normalises both names before it resolves them — `infra/conf/loader.go` lowercases the protocol id, and `TransportProtocol.Build` (`infra/conf/transport_internet.go:16-17`) lowercases the transport name and additionally resolves **both** `"kcp"` and `"mkcp"` to mKCP. **Scenario.** An operator's config spells an outbound `"WireGuard"` — pasted, or hand-edited, or written by another tool — and the core runs it without a word. Someone calls `POST /panel/api/xray/testOutbound` with `mode=tcp` (or `testOutbounds`), as the panel itself did before #6525 and as a script polling the API still does. Then: 1. `outboundTransportIsUDP` compares `"WireGuard"` against `"wireguard"`, gets `false`, and keeps the outbound in the **dial-only TCP lane** — the lane it exists to keep UDP transports out of, because a bare dial neither proves reachability nor measures latency for a protocol that ignores unauthenticated packets. 2. `extractOutboundEndpoints` switches on the raw protocol string, matches no `case`, and returns nothing. 3. The caller gets `No testable endpoint` for an outbound that is passing traffic right now. The transport-name half has the same shape and an extra edge: `"network": "mkcp"` is a spelling the core accepts and builds mKCP from, and it was not recognised at all. The endpoint's own documented contract (`frontend/src/pages/api-docs/endpoints.ts`) states that `mode=tcp` gives fast dial-only probes with UDP-transport outbounds still probed over HTTP — the first step above is where that promise was broken. **What changed** - `outboundTransportIsUDP` matches the proxy protocols and the transport names case-insensitively, and recognises the `mkcp` alias. - `extractOutboundEndpoints` lowercases the protocol id before its switch. **Not changed, deliberately — and one correction to what this description first claimed.** The literal comparisons at `probe_http.go:184-188` (the `blackhole` / `loopback` / `freedom` / `dns` rejections) are still exact in this PR, and this diff stays backend-only. An earlier version of this paragraph said the panel never reaches them with a different spelling, because the frontend skips those outbounds before the request leaves the browser. That is wrong, and this PR's own review disproved it. `isUntestable` (`frontend/src/pages/xray/outbounds/outbounds-tab-helpers.ts:57`) is the only gate on the row's Test button and it compares the id exactly as well, so a `"Freedom"` outbound is probed through the direct outbound and the API answers `success: true` with the panel host's own country and delay — the operator reads the panel's own reachability as a working tunnel. That is a separate, pre-existing bug, fixed in #6527 rather than here. The `blackhole`/`freedom` check in `testOutboundTCP` (`outbound.go:160`) stays exact too: it is message precision only, since `extractOutboundEndpoints` finds no endpoint for those ids either way. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [ ] Frontend (UI / panel pages) - [x] Backend (API endpoints, login, settings) - [ ] Xray config generation - [ ] Subscription (share links / Clash / JSON) - [x] Statistics / traffic counters (the outbound test/probe path) - [ ] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? Three new tests in `internal/web/service/outbound/`, all confirmed red before the fix and green after: - `TestTestOutboundsTCPModeForcesCoreSpelledUDPToHTTPProbe` drives the real `TestOutbounds(..., "tcp")` through a stub xray process and asserts the result comes back from the HTTP probe. Before: `Success:false Error:"No testable endpoint" Mode:"tcp"`. - `TestOutboundTransportIsUDPMatchesTheCore` is a table over both readers' spellings — `WireGuard`, `HYSTERIA`, `KCP`, `mkcp`, `MKCP` must be UDP; `tcp`, `ws` and a plain `vless` must not. Five substests fail before the fix. - `TestTestOutboundsTCPLaneReadsProtocolIDCaseInsensitively` puts a `"SOCKS"` outbound in the TCP lane against a real local listener, so it fails on the extractor alone rather than through the lane gate. Local verification, and one honest caveat about how. This machine has no C compiler, and `internal/database` is a dependency of the package, so it does not build with `CGO_ENABLED=0` on its own — `internal/database/db.go:2812` calls the cgo-only `sqlite3.SQLiteConn.Backup`. I verified with `go test -overlay` pointing at a copy of `db.go` in which that one call is replaced by an error return; **no file this PR changes is substituted**, only that single cgo call. Under that rig: `go test ./internal/web/service/outbound/` passes in full (the pre-existing suite included), `gofmt -l` is clean and `go vet` is clean. Real-CGo compilation, `race`, the Postgres job and the build matrix are left to CI. ## Screenshots / recordings N/A — backend only. ## Breaking changes None. Canonical spellings behave exactly as before; only templates the core already accepts and the probe previously misread change behaviour, and they change from a wrong answer to the right one. ## Checklist - [ ] I tested the change locally and confirmed the described behavior. — Confirmed for the package under the overlay rig described above; `go build ./...` itself needs CGo on this machine. - [x] I added or updated tests for the new behavior (when applicable). - [ ] `go build ./...` and the test suite pass locally. — Blocked by the missing C compiler here; CI covers it. - [ ] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. — No frontend file is touched. - [ ] I updated the Wiki / README / API docs if user-facing behavior changed. — No endpoint, request shape or response field changed; only which lane a request lands in. - [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:01 +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#6332
No description provided.