mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-25 15:25:01 +03:00
fix(sub): close a deleted host binding only on the inbound it served
Deleting the only host a client was bound to blanked that client on every inbound. Once the host row was gone, the binding could no longer say which inbound it guarded, so it failed closed everywhere: a client on inbounds A and B, bound to one host on A, lost B's link the moment that host was deleted, and nothing in the panel hinted at it. Every host delete (host groups, the externalProxy sync, inbound deletion, the depleted-inbound sweep and the orphan prune) now goes through database.DeleteHosts, which keeps each deleted host's inbound in host_tombstones in the same transaction. A binding to a deleted host closes only that inbound; ids that resolve to no host at all still fail closed everywhere. The Postgres Host step now runs the deletion cases as well.
This commit is contained in:
@@ -337,7 +337,7 @@ func (s *HostService) UpdateHostGroup(groupId string, req *entity.HostGroup) ([]
|
||||
}
|
||||
}
|
||||
if len(toDelete) > 0 {
|
||||
if err := tx.Where("id IN ?", toDelete).Delete(&model.Host{}).Error; err != nil {
|
||||
if _, err := database.DeleteHosts(tx, "id IN ?", toDelete); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -360,7 +360,10 @@ func (s *HostService) UpdateHostGroup(groupId string, req *entity.HostGroup) ([]
|
||||
}
|
||||
|
||||
func (s *HostService) DeleteHostGroup(groupId string) error {
|
||||
return database.GetDB().Where("group_id = ?", groupId).Delete(&model.Host{}).Error
|
||||
return database.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
_, err := database.DeleteHosts(tx, "group_id = ?", groupId)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (s *HostService) SetHostGroupEnable(groupId string, enable bool) error {
|
||||
@@ -378,7 +381,10 @@ func (s *HostService) DeleteHostsGroup(groupIds []string) error {
|
||||
if len(groupIds) == 0 {
|
||||
return nil
|
||||
}
|
||||
return database.GetDB().Where("group_id IN ?", groupIds).Delete(&model.Host{}).Error
|
||||
return database.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
_, err := database.DeleteHosts(tx, "group_id IN ?", groupIds)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (s *HostService) ReorderHostGroups(groupIds []string) error {
|
||||
|
||||
@@ -1665,7 +1665,7 @@ func (s *InboundService) delInbound(id int) (bool, func(), error) {
|
||||
if err := tx.Delete(model.Inbound{}, id).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Where("inbound_id = ?", id).Delete(&model.Host{}).Error; err != nil {
|
||||
if _, err := database.DeleteHosts(tx, "inbound_id = ?", id); err != nil {
|
||||
return err
|
||||
}
|
||||
// Drop the deleted inbound from any sub-balancer that selects it; a
|
||||
|
||||
@@ -964,7 +964,7 @@ func (s *InboundService) DelDepletedClients(id int) (err error) {
|
||||
if err := s.clientService.DetachInbound(tx, inbound.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Where("inbound_id = ?", inbound.Id).Delete(&model.Host{}).Error; err != nil {
|
||||
if _, err := database.DeleteHosts(tx, "inbound_id = ?", inbound.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Delete(model.Inbound{}, inbound.Id).Error; err != nil {
|
||||
|
||||
Reference in New Issue
Block a user