mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-09-16 23:27:14 +00:00
fix(node): release a deleted node's metric series and HTTP client
Deleting a node must free what the master keeps per node in memory. Delete dropped the node's cpu and mem series but not netUp and netDown, which the heartbeat records too, so each deleted node leaked two tiered histories. It now drops every NodeMetricKeys entry. InvalidateNode, called on node edit, disable and delete, cleared only the cached Remote. The pooled HTTP client and its transport stayed cached until a later call for the same node pruned them, which a deleted node never makes. InvalidateNode now drops those too, outside the manager lock; an edited node pays one fresh handshake on its next call.
This commit is contained in:
@@ -168,10 +168,15 @@ func sameRemoteIdentity(a, b *model.Node) bool {
|
||||
a.OutboundTag == b.OutboundTag
|
||||
}
|
||||
|
||||
// InvalidateNode forgets everything cached for a node, its pooled HTTP client too:
|
||||
// only a later call for that node would prune it, and a deleted node never makes one.
|
||||
func (m *Manager) InvalidateNode(nodeID int) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
delete(m.remotes, nodeID)
|
||||
m.mu.Unlock()
|
||||
nodeClientsMu.Lock()
|
||||
dropNodeClients(nodeID, "")
|
||||
nodeClientsMu.Unlock()
|
||||
}
|
||||
|
||||
func loadNode(id int) (*model.Node, error) {
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
|
||||
)
|
||||
|
||||
// Only a later call for the same node pruned its pooled client, so a deleted
|
||||
// node kept its client and transport cached for the life of the process.
|
||||
func TestInvalidateNodeDropsItsCachedHTTPClient(t *testing.T) {
|
||||
node := &model.Node{Id: 8801, Address: "node.example.test", Port: 443, Scheme: "https", TlsVerifyMode: "skip"}
|
||||
if _, err := HTTPClientForNode(node, ""); err != nil {
|
||||
t.Fatalf("HTTPClientForNode: %v", err)
|
||||
}
|
||||
if got := nodeClientEntries(node.Id); got != 1 {
|
||||
t.Fatalf("cached clients before invalidation = %d, want 1", got)
|
||||
}
|
||||
|
||||
NewManager(LocalDeps{}).InvalidateNode(node.Id)
|
||||
|
||||
if got := nodeClientEntries(node.Id); got != 0 {
|
||||
t.Fatalf("cached clients after InvalidateNode = %d, want 0", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user