mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6549] [MERGED] fix(inbounds): check ports when an inbound is enabled, not only when it is saved #6347
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#6347
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?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6549
Author: @BlindMaster24
Created: 9/15/2026
Status: ✅ Merged
Merged: 9/15/2026
Merged by: @BlindMaster24
Base:
main← Head:fix/inbound-enable-port-check📝 Commits (2)
f53e0c1fix(inbounds): check ports when an inbound is enabled, not only when it is savedbd32435docs(inbounds): state the real reason the enable path needs its own check📊 Changes
2 files changed (+94 additions, -0 deletions)
View changed files
📝
internal/web/service/inbound.go(+11 -0)➕
internal/web/service/inbound_enable_port_test.go(+83 -0)📄 Description
What breaks today
SetInboundEnable(inbound.go:1574) flips theenablecolumn and, for a node row, polls the remote — with no port check on that path at all. Every guard in the panel lives on the save path:checkPortConflictTxruns fromAddInbound(inbound.go:1229) andUpdateInbound(inbound.go:1729), and nowhere else. So a row can reach the enabled state having never been checked, whenever the pair was not produced through a guarded save:#6539,#6540,#6542), so an installation upgrading across them can hold a same-port pair in its DB;AddInbound.Once the flag moves, the generated config has two inbounds on one socket, and the core does not skip the second one — it exits the whole process on the failed listen (
main/run.go:94), taking every protocol on the host down, then the one-second watchdog retries it. Reached from the UI with the enable switch; no unusual steps.The change
Check the same rules before the flag moves, and only for a local enable — nodes run their own Xray, so a node row sharing a local port stays legal, and enabling is the direction that can create a collision (disabling cannot):
The refusal is
common.NewError(conflict.String()), the same shapeAddInbound/UpdateInboundalready return, so the panel shows which row owns the port ('holder' (#2) port 44431 (tcp)). Because the check runs before the transaction, a refused enable leaves the row disabled — no half-applied switch.Reuse, not a new rule: this is the existing checker with all of its special cases (tcp/udp coexistence, reserved API and egress ports, AmneziaWG relay slots, node exemption), so an enable can no longer be refused for something a save would have allowed.
Note this is the same funnel question the previous PRs closed from the config side: with #6547 a colliding config is refused before the core is swapped, so the failure is loud either way — but refusing at the switch is where the operator can act, and it keeps the log from being the only report.
Red first, with the exact output
TestSetInboundEnableRefusesAPortAnotherEnabledInboundServes— two rows on0.0.0.0:44431, the second disabled through the DB, then the enable switch:Green after the change, and it asserts the two things that matter beyond the error: the message names
holder, and the row is still disabled afterwards.The state is seeded with
seedInboundConflict(a directdb.Create) plus a rawUpdate("enable", false)on purpose:AddInboundtreats a disabled row as owning its port (port_conflict.go:245-252has noenablepredicate), so the API refuses to build this pair in the first place — which is exactly the class of row this guard is for.Two guards against the fix being too broad, both green before and after:
TestSetInboundEnableAllowsTCPUDPCoexistence— avless/tcprow enabling onto a port ahysteria/udprow holds, the legal coexistence the rest of the guards allow.TestSetInboundEnableAllowsANodeRowOnALocalPort— a node row enabling onto a local row's port.The pre-existing
TestSetInboundEnableRoutedMtprotoRequestsRestartstill passes, so the MTProto restart path through this function is untouched.Gate
go test ./internal/web/service -shuffle=on— green, 255 s (local run through a-overlaysupplying a pure-Go SQLite driver; the tree'sgo.mod/go.sumare unchanged). AllTestAddInbound*,TestUpdateInbound*andTestSetInboundEnable*tests included.go test ./internal/web/joband./internal/web/controller— green.gofmt -landgo veton the touched packages — clean.go-test,golangci,race.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.