fix(inbounds): check ports when an inbound is enabled, not only when it is saved (#6549)

* fix(inbounds): check ports when an inbound is enabled, not only when it is saved

The save-time guards compare enabled rows, so a row could be created while
another disabled row held its port and only collide once the disabled one was
switched on. Run the same checks before the flag moves: the refusal names the
row that owns the port, the flag is left alone, and tcp/udp coexistence and
node rows keep working.

* docs(inbounds): state the real reason the enable path needs its own check
This commit is contained in:
BlindMaster24
2026-09-15 15:29:32 +03:00
committed by GitHub
parent baef3cdd07
commit 574caa63e9
2 changed files with 94 additions and 0 deletions
+11
View File
@@ -1581,6 +1581,17 @@ func (s *InboundService) SetInboundEnable(id int, enable bool) (bool, error) {
}
db := database.GetDB()
// Enabling puts this row's ports into the running config, and the guards ran
// only if it was saved: a restored or hand-edited row reaches it unchecked.
if enable && inbound.NodeID == nil {
conflict, err := checkPortConflictTx(db, inbound, inbound.Id)
if err != nil {
return false, err
}
if conflict != nil {
return false, common.NewError(conflict.String())
}
}
if err := db.Transaction(func(tx *gorm.DB) error {
if err := tx.Model(model.Inbound{}).Where("id = ?", id).
Update("enable", enable).Error; err != nil {