mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-10-05 09:36:37 +08:00
fix(backend): properly identify and clean up orphaned tunnel_%d services
This commit is contained in:
@@ -556,6 +556,14 @@ func (h *Handler) cleanOrphanedServices(nodeID int64, services []namedConfigItem
|
|||||||
}
|
}
|
||||||
|
|
||||||
parts := strings.Split(name, "_")
|
parts := strings.Split(name, "_")
|
||||||
|
if len(parts) == 2 && parts[0] == "tunnel" {
|
||||||
|
tunnelID, err := strconv.ParseInt(parts[1], 10, 64)
|
||||||
|
if err == nil && tunnelID > 0 && !h.tunnelExists(tunnelID) {
|
||||||
|
_, _ = h.sendNodeCommand(nodeID, "DeleteService", map[string]interface{}{"services": []string{name}}, false, true)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if len(parts) >= 3 {
|
if len(parts) >= 3 {
|
||||||
forwardID, err := strconv.ParseInt(parts[0], 10, 64)
|
forwardID, err := strconv.ParseInt(parts[0], 10, 64)
|
||||||
if err == nil && forwardID > 0 && hasUnboundForwardPeerRuntime {
|
if err == nil && forwardID > 0 && hasUnboundForwardPeerRuntime {
|
||||||
@@ -569,7 +577,7 @@ func (h *Handler) cleanOrphanedServices(nodeID int64, services []namedConfigItem
|
|||||||
suffix := parts[len(parts)-1]
|
suffix := parts[len(parts)-1]
|
||||||
|
|
||||||
switch suffix {
|
switch suffix {
|
||||||
case "tls":
|
case "tls", "kcp", "wss", "mtls", "mwss", "mtcp":
|
||||||
tunnelID, err := strconv.ParseInt(parts[0], 10, 64)
|
tunnelID, err := strconv.ParseInt(parts[0], 10, 64)
|
||||||
if err != nil || tunnelID <= 0 || h.tunnelExists(tunnelID) {
|
if err != nil || tunnelID <= 0 || h.tunnelExists(tunnelID) {
|
||||||
continue
|
continue
|
||||||
@@ -577,6 +585,10 @@ func (h *Handler) cleanOrphanedServices(nodeID int64, services []namedConfigItem
|
|||||||
_, _ = h.sendNodeCommand(nodeID, "DeleteService", map[string]interface{}{"services": []string{name}}, false, true)
|
_, _ = h.sendNodeCommand(nodeID, "DeleteService", map[string]interface{}{"services": []string{name}}, false, true)
|
||||||
case "tcp":
|
case "tcp":
|
||||||
if len(parts) < 4 {
|
if len(parts) < 4 {
|
||||||
|
tunnelID, err := strconv.ParseInt(parts[0], 10, 64)
|
||||||
|
if err == nil && tunnelID > 0 && !h.tunnelExists(tunnelID) {
|
||||||
|
_, _ = h.sendNodeCommand(nodeID, "DeleteService", map[string]interface{}{"services": []string{name}}, false, true)
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
forwardID, err := strconv.ParseInt(parts[0], 10, 64)
|
forwardID, err := strconv.ParseInt(parts[0], 10, 64)
|
||||||
|
|||||||
@@ -730,17 +730,26 @@ func (h *Handler) cleanupTunnelRuntime(tunnelID int64) {
|
|||||||
if protocol == "" {
|
if protocol == "" {
|
||||||
protocol = "tls"
|
protocol = "tls"
|
||||||
}
|
}
|
||||||
serviceName := fmt.Sprintf("%d_%s", tunnelID, protocol)
|
|
||||||
chainName := fmt.Sprintf("chains_%d", tunnelID)
|
chainName := fmt.Sprintf("chains_%d", tunnelID)
|
||||||
|
serviceNames := []string{
|
||||||
|
fmt.Sprintf("tunnel_%d", tunnelID),
|
||||||
|
fmt.Sprintf("%d_tls", tunnelID),
|
||||||
|
fmt.Sprintf("%d_kcp", tunnelID),
|
||||||
|
fmt.Sprintf("%d_wss", tunnelID),
|
||||||
|
fmt.Sprintf("%d_mtls", tunnelID),
|
||||||
|
fmt.Sprintf("%d_mwss", tunnelID),
|
||||||
|
fmt.Sprintf("%d_tcp", tunnelID),
|
||||||
|
fmt.Sprintf("%d_mtcp", tunnelID),
|
||||||
|
}
|
||||||
|
|
||||||
for _, row := range chainRows {
|
for _, row := range chainRows {
|
||||||
if row.ChainType == 1 {
|
if row.ChainType == 1 {
|
||||||
_, _ = h.sendNodeCommand(row.NodeID, "DeleteChains", map[string]interface{}{"chain": chainName}, false, true)
|
_, _ = h.sendNodeCommand(row.NodeID, "DeleteChains", map[string]interface{}{"chain": chainName}, false, true)
|
||||||
} else if row.ChainType == 2 {
|
} else if row.ChainType == 2 {
|
||||||
_, _ = h.sendNodeCommand(row.NodeID, "DeleteChains", map[string]interface{}{"chain": chainName}, false, true)
|
_, _ = h.sendNodeCommand(row.NodeID, "DeleteChains", map[string]interface{}{"chain": chainName}, false, true)
|
||||||
_, _ = h.sendNodeCommand(row.NodeID, "DeleteService", map[string]interface{}{"services": []string{serviceName}}, false, true)
|
_, _ = h.sendNodeCommand(row.NodeID, "DeleteService", map[string]interface{}{"services": serviceNames}, false, true)
|
||||||
} else if row.ChainType == 3 {
|
} else if row.ChainType == 3 {
|
||||||
_, _ = h.sendNodeCommand(row.NodeID, "DeleteService", map[string]interface{}{"services": []string{serviceName}}, false, true)
|
_, _ = h.sendNodeCommand(row.NodeID, "DeleteService", map[string]interface{}{"services": serviceNames}, false, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user