mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6841] [Bug]: Clash subscription drops numeric XMUX fields (default maxConnections: 3 never reaches clients) #4550
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#4550
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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-settingswhen the value is a string (internal/sub/clash_service.go,buildXhttpClashOpts):maxConnectionsandcMaxReuseTimescan be numbers, though: the schema allowsz.union([z.string(), z.number()]). And when you turn on the XMUX switch, the panel fills inXMUX_FRESH_DEFAULTSwithmaxConnections: 3as 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-settingswith neithermax-concurrencynormax-connections, it puts every request on a single connection with no stream limit (transport/xhttp/reuse.go:shouldCreateLockedonly creates the first entry, andpickLockedhas no concurrency cap). On a ~180 ms RTT path, a multi-threaded speed test through XHTTP got 90 Mbps with these defaults. After I setmaxConnectionsto 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
3).reuse-settingscontains onlyh-max-request-timesandh-max-reusable-secs.max-connectionsis missing.Entering a range such as
4-8works, because the value is then stored as a string.Expected behavior
reuse-settingsincludesmax-connections: "3". Any non-zero numeric XMUX value should be passed through as a string.Actual behavior
Numeric
maxConnections/cMaxReuseTimesare silently dropped.Suggested fix
Accept numbers in that loop. The file already has
nonZeroShareValueforhKeepAlivePeriod, so it could be reused:The existing tests in
clash_service_test.goonly use string values ("4","8"), so this case isn't covered.Environment
Before submitting
@MHSanaei commented on GitHub (Oct 16, 2026):
@claude analyze
@github-actions[bot] commented on GitHub (Oct 16, 2026):
Confirmed. The Clash/Mihomo subscription only copies an XMUX value into
reuse-settingswhen it is a string. The default XMUX seed storesmaxConnectionsas the number3, so with default settingsmax-connectionsnever reaches the client. Until this is fixed, you can work around it by typing the value into the Max Connections field yourself (e.g.3or4-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: (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 forcMaxReuseTimes(xhttp.ts:25-26).resolveXmuxExclusivityinfrontend/src/lib/xray/stream-wire-normalize.ts:63keeps the value's type when it saves, so a field you never edit is stored as the JSON number3.Where it is dropped
internal/sub/clash_service.go:1020, inbuildXhttpClashOpts:A JSON number decodes to
float64, so the type assertion fails and the field is skipped without any error. The default seed setsmaxConcurrencyto'', so in the default casereuse-settingsends up with onlyh-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.hKeepAlivePeriodon the next line already goes throughnonZeroShareValue, so it handles both types.The other subscription formats are not affected. Share links copy the whole
xmuxobject throughnonEmptyShareObject(internal/sub/service.go:2581-2584), and the JSON subscription passesxhttpSettingsthrough unchanged. The existing test only uses string inputs ("maxConnections": "4","cMaxReuseTimes": "8"atinternal/sub/clash_service_test.go:499-500), so this case has no test coverage.Suggested fix: In the loop at
clash_service.go:1013-1022, replace the.(string)assertion withnonZeroShareValueand stringify the result, which mirrors howhKeepAlivePeriodis handled. Stringify withstrconv.FormatFloat(v, 'f', -1, 64)(or an equivalent) rather thanfmt.Sprint, because%von afloat64renders large whole numbers in exponent form (e.g.1e+06). Add a test case withfloat64values formaxConnectionsandcMaxReuseTimes. That test should fail against the current code.This reply was generated automatically; a maintainer may follow up.