[GH-ISSUE #6841] [Bug]: Clash subscription drops numeric XMUX fields (default maxConnections: 3 never reaches clients) #4550

Closed
opened 2026-10-31 20:40:26 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @PosvdM on GitHub (Oct 15, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6841

Describe the bug

The Clash subscription only copies an XMUX field into reuse-settings when the value is a string (internal/sub/clash_service.go, buildXhttpClashOpts):

if v, ok := xmux[f.src].(string); ok && v != "" {

maxConnections and cMaxReuseTimes can be numbers, though: the schema allows z.union([z.string(), z.number()]). And when you turn on the XMUX switch, the panel fills in XMUX_FRESH_DEFAULTS with maxConnections: 3 as a number. As a result, the default XMUX config never reaches Clash clients.

This changes behavior instead of just losing a setting. When mihomo receives reuse-settings with neither max-concurrency nor max-connections, it puts every request on a single connection with no stream limit (transport/xhttp/reuse.go: shouldCreateLocked only creates the first entry, and pickLocked has no concurrency cap). On a ~180 ms RTT path, a multi-threaded speed test through XHTTP got 90 Mbps with these defaults. After I set maxConnections to the string "4-8", it got 270–300 Mbps, the same as a VLESS-REALITY-TCP inbound on the same server.

How to reproduce the problem

  1. Create a VLESS + XHTTP + REALITY inbound.
  2. Turn on XMUX and keep the defaults (max connections shows 3).
  3. Save, then fetch the Clash subscription for a client of that inbound.
  4. reuse-settings contains only h-max-request-times and h-max-reusable-secs. max-connections is missing.

Entering a range such as 4-8 works, because the value is then stored as a string.

Expected behavior

reuse-settings includes max-connections: "3". Any non-zero numeric XMUX value should be passed through as a string.

Actual behavior

Numeric maxConnections / cMaxReuseTimes are silently dropped.

Suggested fix

Accept numbers in that loop. The file already has nonZeroShareValue for hKeepAlivePeriod, so it could be reused:

if v, ok := nonZeroShareValue(xmux[f.src]); ok {
    reuse[f.dst] = fmt.Sprint(v)
}

The existing tests in clash_service_test.go only use string values ("4", "8"), so this case isn't covered.

Environment

  • 3x-ui version: 3.10.2
  • Xray-core version: 26.10.10
  • Install method: install.sh script
  • OS: Ubuntu 24.04 (aarch64)
  • Affected area: Subscription (share links / Clash / JSON)
  • Reverse proxy / CDN: Yes — Nginx (OpenResty via 1Panel)

Before submitting

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui.
  • This bug report is written in English.
  • I have redacted any sensitive data.
Originally created by @PosvdM on GitHub (Oct 15, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6841 ### Describe the bug The Clash subscription only copies an XMUX field into `reuse-settings` when the value is a string (`internal/sub/clash_service.go`, `buildXhttpClashOpts`): ```go if v, ok := xmux[f.src].(string); ok && v != "" { ``` `maxConnections` and `cMaxReuseTimes` can be numbers, though: the schema allows `z.union([z.string(), z.number()])`. And when you turn on the XMUX switch, the panel fills in `XMUX_FRESH_DEFAULTS` with `maxConnections: 3` as a number. As a result, the default XMUX config never reaches Clash clients. This changes behavior instead of just losing a setting. When mihomo receives `reuse-settings` with neither `max-concurrency` nor `max-connections`, it puts every request on a single connection with no stream limit (`transport/xhttp/reuse.go`: `shouldCreateLocked` only creates the first entry, and `pickLocked` has no concurrency cap). On a ~180 ms RTT path, a multi-threaded speed test through XHTTP got 90 Mbps with these defaults. After I set `maxConnections` to the string `"4-8"`, it got 270–300 Mbps, the same as a VLESS-REALITY-TCP inbound on the same server. ### How to reproduce the problem 1. Create a VLESS + XHTTP + REALITY inbound. 2. Turn on XMUX and keep the defaults (max connections shows `3`). 3. Save, then fetch the Clash subscription for a client of that inbound. 4. `reuse-settings` contains only `h-max-request-times` and `h-max-reusable-secs`. `max-connections` is missing. Entering a range such as `4-8` works, because the value is then stored as a string. ### Expected behavior `reuse-settings` includes `max-connections: "3"`. Any non-zero numeric XMUX value should be passed through as a string. ### Actual behavior Numeric `maxConnections` / `cMaxReuseTimes` are silently dropped. ### Suggested fix Accept numbers in that loop. The file already has `nonZeroShareValue` for `hKeepAlivePeriod`, so it could be reused: ```go if v, ok := nonZeroShareValue(xmux[f.src]); ok { reuse[f.dst] = fmt.Sprint(v) } ``` The existing tests in `clash_service_test.go` only use string values (`"4"`, `"8"`), so this case isn't covered. ### Environment - **3x-ui version:** 3.10.2 - **Xray-core version:** 26.10.10 - **Install method:** install.sh script - **OS:** Ubuntu 24.04 (aarch64) - **Affected area:** Subscription (share links / Clash / JSON) - **Reverse proxy / CDN:** Yes — Nginx (OpenResty via 1Panel) ### Before submitting - [x] I searched existing issues and this bug has not been reported. - [x] I am running the latest released version of 3x-ui. - [x] This bug report is written in English. - [x] I have redacted any sensitive data.
bsakaguchi 2026-10-31 20:40:26 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@MHSanaei commented on GitHub (Oct 16, 2026):

@claude analyze

<!-- gh-comment-id:6212795231 --> @MHSanaei commented on GitHub (Oct 16, 2026): @claude analyze
Author
Owner

@github-actions[bot] commented on GitHub (Oct 16, 2026):

Confirmed. The Clash/Mihomo subscription only copies an XMUX value into reuse-settings when it is a string. The default XMUX seed stores maxConnections as the number 3, so with default settings max-connections never reaches the client. Until this is fixed, you can work around it by typing the value into the Max Connections field yourself (e.g. 3 or 4-8). The form field is a text <Input>, so anything you type is saved as a string and passes the check.

This is the first analysis of this issue.

How the number gets into the config

  • frontend/src/schemas/protocols/stream/xhttp.ts:38-42: turning XMUX on seeds this object:
    export const XMUX_FRESH_DEFAULTS: XHttpXmux = {
      ...XHttpXmuxSchema.parse({}),
      maxConcurrency: '',
      maxConnections: 3,
    };
    
    (frontend/src/pages/inbounds/form/transport/xhttp.tsx:55). The schema allows either type: maxConnections: z.union([z.string(), z.number()]).default(0) and the same for cMaxReuseTimes (xhttp.ts:25-26). resolveXmuxExclusivity in frontend/src/lib/xray/stream-wire-normalize.ts:63 keeps the value's type when it saves, so a field you never edit is stored as the JSON number 3.

Where it is dropped

internal/sub/clash_service.go:1020, in buildXhttpClashOpts:

if v, ok := xmux[f.src].(string); ok && v != "" {

A JSON number decodes to float64, so the type assertion fails and the field is skipped without any error. The default seed sets maxConcurrency to '', so in the default case reuse-settings ends up with only h-max-request-times / h-max-reusable-secs, exactly as you reported.

The same check applies to all five fields in that loop (maxConcurrency, maxConnections, cMaxReuseTimes, hMaxRequestTimes, hMaxReusableSecs). Any of them saved as a number is lost too, for example from a JSON-edited or API-created inbound. Xray's Int32Range accepts numbers there; that is an inference, not checked in this repo. hKeepAlivePeriod on the next line already goes through nonZeroShareValue, so it handles both types.

The other subscription formats are not affected. Share links copy the whole xmux object through nonEmptyShareObject (internal/sub/service.go:2581-2584), and the JSON subscription passes xhttpSettings through unchanged. The existing test only uses string inputs ("maxConnections": "4", "cMaxReuseTimes": "8" at internal/sub/clash_service_test.go:499-500), so this case has no test coverage.

Verdict:        Confirmed bug
Severity:       Medium
Confidence:     High
Root cause:     internal/sub/clash_service.go:1020 (buildXhttpClashOpts) — the XMUX → reuse-settings loop accepts only string values; numeric values (float64 after JSON decode) are dropped. Default XMUX seeds maxConnections: 3 as a number (frontend/src/schemas/protocols/stream/xhttp.ts:41, added in 7f7b7e16 "feat(xray): update xray-core to v26.7.28 and adapt panel"). String-only check introduced in 1a4aef33 "feat(sub): full XHTTP field mapping for Clash/Mihomo subscriptions (#5417)", first released in v3.4.0.
Same class:     All five fields in the same loop (clash_service.go:1013-1019); the other XHTTP string loops at clash_service.go:965 and :981 make the same .(string) check, but those fields are string-typed in the schema. None found in share-link (service.go:2581) or JSON subscription paths.
Already fixed:  Still present on the default branch (608ef4e4, v3.10.2).
Duplicate of:   None
Evidence:       clash_service.go:1020 `xmux[f.src].(string)`; clash_service.go:1024 `nonZeroShareValue(xmux["hKeepAlivePeriod"])`; xhttp.ts:25-26,38-42; inbounds/form/transport/xhttp.tsx:55 (seed), :336-340 (text Input); clash_service_test.go:497-504 (string-only fixtures).
Not determined: The Mihomo-side behaviour (one connection with no concurrency cap when neither max-concurrency nor max-connections is set) and the throughput numbers are in mihomo's code, not this repo, so I could not check them here. Fetching a Clash subscription for an inbound with untouched XMUX defaults would confirm the missing key; your step 4 already shows it.

Suggested fix: In the loop at clash_service.go:1013-1022, replace the .(string) assertion with nonZeroShareValue and stringify the result, which mirrors how hKeepAlivePeriod is handled. Stringify with strconv.FormatFloat(v, 'f', -1, 64) (or an equivalent) rather than fmt.Sprint, because %v on a float64 renders large whole numbers in exponent form (e.g. 1e+06). Add a test case with float64 values for maxConnections and cMaxReuseTimes. That test should fail against the current code.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:6212819414 --> @github-actions[bot] commented on GitHub (Oct 16, 2026): Confirmed. The Clash/Mihomo subscription only copies an XMUX value into `reuse-settings` when it is a string. The default XMUX seed stores `maxConnections` as the number `3`, so with default settings `max-connections` never reaches the client. Until this is fixed, you can work around it by typing the value into the **Max Connections** field yourself (e.g. `3` or `4-8`). The form field is a text `<Input>`, so anything you type is saved as a string and passes the check. This is the first analysis of this issue. **How the number gets into the config** - `frontend/src/schemas/protocols/stream/xhttp.ts:38-42`: turning XMUX on seeds this object: ```ts export const XMUX_FRESH_DEFAULTS: XHttpXmux = { ...XHttpXmuxSchema.parse({}), maxConcurrency: '', maxConnections: 3, }; ``` (`frontend/src/pages/inbounds/form/transport/xhttp.tsx:55`). The schema allows either type: `maxConnections: z.union([z.string(), z.number()]).default(0)` and the same for `cMaxReuseTimes` (`xhttp.ts:25-26`). `resolveXmuxExclusivity` in `frontend/src/lib/xray/stream-wire-normalize.ts:63` keeps the value's type when it saves, so a field you never edit is stored as the JSON number `3`. **Where it is dropped** `internal/sub/clash_service.go:1020`, in `buildXhttpClashOpts`: ```go if v, ok := xmux[f.src].(string); ok && v != "" { ``` A JSON number decodes to `float64`, so the type assertion fails and the field is skipped without any error. The default seed sets `maxConcurrency` to `''`, so in the default case `reuse-settings` ends up with only `h-max-request-times` / `h-max-reusable-secs`, exactly as you reported. The same check applies to all five fields in that loop (`maxConcurrency`, `maxConnections`, `cMaxReuseTimes`, `hMaxRequestTimes`, `hMaxReusableSecs`). Any of them saved as a number is lost too, for example from a JSON-edited or API-created inbound. Xray's Int32Range accepts numbers there; that is an inference, not checked in this repo. `hKeepAlivePeriod` on the next line already goes through `nonZeroShareValue`, so it handles both types. The other subscription formats are not affected. Share links copy the whole `xmux` object through `nonEmptyShareObject` (`internal/sub/service.go:2581-2584`), and the JSON subscription passes `xhttpSettings` through unchanged. The existing test only uses string inputs (`"maxConnections": "4"`, `"cMaxReuseTimes": "8"` at `internal/sub/clash_service_test.go:499-500`), so this case has no test coverage. ``` Verdict: Confirmed bug Severity: Medium Confidence: High Root cause: internal/sub/clash_service.go:1020 (buildXhttpClashOpts) — the XMUX → reuse-settings loop accepts only string values; numeric values (float64 after JSON decode) are dropped. Default XMUX seeds maxConnections: 3 as a number (frontend/src/schemas/protocols/stream/xhttp.ts:41, added in 7f7b7e16 "feat(xray): update xray-core to v26.7.28 and adapt panel"). String-only check introduced in 1a4aef33 "feat(sub): full XHTTP field mapping for Clash/Mihomo subscriptions (#5417)", first released in v3.4.0. Same class: All five fields in the same loop (clash_service.go:1013-1019); the other XHTTP string loops at clash_service.go:965 and :981 make the same .(string) check, but those fields are string-typed in the schema. None found in share-link (service.go:2581) or JSON subscription paths. Already fixed: Still present on the default branch (608ef4e4, v3.10.2). Duplicate of: None Evidence: clash_service.go:1020 `xmux[f.src].(string)`; clash_service.go:1024 `nonZeroShareValue(xmux["hKeepAlivePeriod"])`; xhttp.ts:25-26,38-42; inbounds/form/transport/xhttp.tsx:55 (seed), :336-340 (text Input); clash_service_test.go:497-504 (string-only fixtures). Not determined: The Mihomo-side behaviour (one connection with no concurrency cap when neither max-concurrency nor max-connections is set) and the throughput numbers are in mihomo's code, not this repo, so I could not check them here. Fetching a Clash subscription for an inbound with untouched XMUX defaults would confirm the missing key; your step 4 already shows it. ``` **Suggested fix:** In the loop at `clash_service.go:1013-1022`, replace the `.(string)` assertion with `nonZeroShareValue` and stringify the result, which mirrors how `hKeepAlivePeriod` is handled. Stringify with `strconv.FormatFloat(v, 'f', -1, 64)` (or an equivalent) rather than `fmt.Sprint`, because `%v` on a `float64` renders large whole numbers in exponent form (e.g. `1e+06`). Add a test case with `float64` values for `maxConnections` and `cMaxReuseTimes`. That test should fail against the current code. *This reply was generated automatically; a maintainer may follow up.* <!-- claude-issue:analyst -->
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#4550
No description provided.