fix(nodes): clean up orphaned client_inbounds on node inbound removal

When a remote node disconnects or one of its inbounds vanishes from the
traffic snapshot, setRemoteTrafficLocked deleted the central inbound row
but left the client_inbounds join rows behind. Affected clients ended up
linked to hundreds of phantom inbounds, and editing one then failed with
"record not found" / "Load Old Data Error" because Update aborted on the
first GetInbound miss.

- Detach client_inbounds rows when deleting a vanished node inbound
- Prune stale links during client Update instead of aborting the save
- Drop orphaned client_inbounds rows on startup to heal existing DBs

Closes #4636
This commit is contained in:
MHSanaei
2026-05-29 01:41:52 +02:00
parent b395a1b951
commit 169068d8fb
3 changed files with 26 additions and 0 deletions
+15
View File
@@ -83,6 +83,21 @@ func initModels() error {
return err
}
}
if err := pruneOrphanedClientInbounds(); err != nil {
return err
}
return nil
}
func pruneOrphanedClientInbounds() error {
res := db.Exec("DELETE FROM client_inbounds WHERE inbound_id NOT IN (SELECT id FROM inbounds)")
if res.Error != nil {
log.Printf("Error pruning orphaned client_inbounds rows: %v", res.Error)
return res.Error
}
if res.RowsAffected > 0 {
log.Printf("Pruned %d orphaned client_inbounds row(s)", res.RowsAffected)
}
return nil
}