[PR #5833] [MERGED] fix(inbound): scope port-conflict check to the stored node on update #6002

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5833
Author: @yukh975
Created: 7/6/2026
Status: ✅ Merged
Merged: 7/8/2026
Merged by: @MHSanaei

Base: main ← Head: fix/node-inbound-port-conflict


📝 Commits (3)

  • 45871f2 fix(inbound): scope port-conflict check to the stored node on update
  • 1198713 Merge branch 'main' into fix/node-inbound-port-conflict
  • beee9a1 style(inbound): trim inline comments from port-conflict scoping

📊 Changes

2 files changed (+32 additions, -5 deletions)

View changed files

📝 internal/web/service/inbound.go (+8 -5)
📝 internal/web/service/inbound_update_tag_test.go (+24 -0)

📄 Description

Problem

Editing an inbound that belongs to a node is rejected with a spurious port-conflict error when an unrelated inbound on the central panel (or another node) happens to reuse the same port. For example, changing a node inbound's listen address fails with:

port 10000 (tcp) already used by inbound 'X' (#1) on *

and the edit is silently discarded. The two inbounds run on different machines, so there is no real conflict.

Root cause

InboundService.UpdateInbound runs checkPortConflict before it restores the inbound's NodeID from the database:

conflict, err := s.checkPortConflict(inbound, inbound.Id)   // uses request NodeID
...
oldInbound, _ := s.GetInbound(inbound.Id)
inbound.NodeID = oldInbound.NodeID                          // restored afterwards

The request body's nodeId is unreliable for edits — it is json:",omitempty" and the UI omits it — which is exactly why the code overwrites it with the stored value. But the conflict check has already run with inbound.NodeID == nil, so a node inbound is treated as a local/main-panel inbound. checkPortConflict correctly scopes candidates by node (sameNode); it was simply being fed the wrong NodeID.

Fix

Restore inbound.NodeID from the stored row before the conflict check, so it runs against the node the inbound actually lives on. AddInbound is unaffected (there the request's nodeId is authoritative at creation time).

Test

Adds TestUpdateInbound_NodeInboundNotBlockedByLocalSamePort: seeds a main-panel inbound and a node inbound on the same port, edits the node inbound's listen address with nodeId omitted, and asserts it is not rejected as a conflict. Fails before this change with the exact "already used" error; passes after. go test ./internal/web/service/, gofmt and go vet are green.


🔄 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/5833 **Author:** [@yukh975](https://github.com/yukh975) **Created:** 7/6/2026 **Status:** ✅ Merged **Merged:** 7/8/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/node-inbound-port-conflict` --- ### 📝 Commits (3) - [`45871f2`](https://github.com/MHSanaei/3x-ui/commit/45871f267319da0f96ee2b4d583b8ebbf0261dae) fix(inbound): scope port-conflict check to the stored node on update - [`1198713`](https://github.com/MHSanaei/3x-ui/commit/11987138f4f1f2ac4b78067c1714ee54c6f42b41) Merge branch 'main' into fix/node-inbound-port-conflict - [`beee9a1`](https://github.com/MHSanaei/3x-ui/commit/beee9a174d7527629b866af5bd2909d3e9869471) style(inbound): trim inline comments from port-conflict scoping ### 📊 Changes **2 files changed** (+32 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/service/inbound.go` (+8 -5) 📝 `internal/web/service/inbound_update_tag_test.go` (+24 -0) </details> ### 📄 Description ### Problem Editing an inbound that belongs to a **node** is rejected with a spurious port-conflict error when an **unrelated** inbound on the central panel (or another node) happens to reuse the same port. For example, changing a node inbound's listen address fails with: > port 10000 (tcp) already used by inbound 'X' (#1) on * and the edit is silently discarded. The two inbounds run on different machines, so there is no real conflict. ### Root cause `InboundService.UpdateInbound` runs `checkPortConflict` **before** it restores the inbound's `NodeID` from the database: ```go conflict, err := s.checkPortConflict(inbound, inbound.Id) // uses request NodeID ... oldInbound, _ := s.GetInbound(inbound.Id) inbound.NodeID = oldInbound.NodeID // restored afterwards ``` The request body's `nodeId` is unreliable for edits — it is `json:",omitempty"` and the UI omits it — which is exactly why the code overwrites it with the stored value. But the conflict check has already run with `inbound.NodeID == nil`, so a node inbound is treated as a local/main-panel inbound. `checkPortConflict` correctly scopes candidates by node (`sameNode`); it was simply being fed the wrong `NodeID`. ### Fix Restore `inbound.NodeID` from the stored row **before** the conflict check, so it runs against the node the inbound actually lives on. `AddInbound` is unaffected (there the request's `nodeId` is authoritative at creation time). ### Test Adds `TestUpdateInbound_NodeInboundNotBlockedByLocalSamePort`: seeds a main-panel inbound and a node inbound on the same port, edits the node inbound's listen address with `nodeId` omitted, and asserts it is not rejected as a conflict. Fails before this change with the exact "already used" error; passes after. `go test ./internal/web/service/`, `gofmt` and `go vet` are green. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:05:40 +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#6002
No description provided.