fix(panel): break Xray restart deadlock and bound panel reload (#7346)

Fix the production-confirmed ABBA lock inversion introduced in v3.12.0: Xray restart held the lifecycle mutex while synchronously waiting for the serialized traffic writer, which needed the same mutex to amend the committed live configuration snapshot. This blocked API writes and node synchronization, and made panel reload wait indefinitely for cron shutdown.

Run traffic maintenance before acquiring the Xray lifecycle mutex, keep config generation free of writer submissions, and retain the live-snapshot generation guard. Bound panel-only reload with one 75-second deadline across shutdown and startup; fence replacement workers until the old generation drains, and exit nonzero for supervised recovery on failure. Preserve Xray on healthy reloads, gracefully handle termination signals, log phase timings and bounded function-only stack diagnostics, and distinguish accepted restart requests from successful completion.

Validation: all 13 GitHub checks passed on the reviewed head, including Go tests, race, PostgreSQL durable-first/migration, node and Xray E2E, frontend, lint, codegen, vulnerability check and docs. PR validation reports isolated SQLite/PostgreSQL 18 reload tests with 15,844 clients and 30,270 memberships, stable real Xray PIDs, and legacy/current node interoperability.

Addresses the primary deadlock and bounded panel reload; writer cancellation and per-source listener admission diagnostics remain follow-ups. Supervised failure recovery may interrupt Xray sessions.

Fixes #7345
This commit is contained in:
Hamed
2026-12-02 11:40:21 +03:30
committed by GitHub
parent 267379456a
commit b2d7a9bb08
26 changed files with 475 additions and 76 deletions
+23 -5
View File
@@ -16,6 +16,7 @@ import (
"strconv"
"strings"
"sync"
"sync/atomic"
"testing"
"time"
@@ -49,14 +50,31 @@ type panel struct {
logOut *os.File
}
// The fixture processes bind after their databases have been prepared. Keep
// each assignment unique for the run and below the default ephemeral range on
// CI, where outbound HTTP connections could otherwise take the same port.
var fixturePortOffset atomic.Uint32
func freePort(t *testing.T) int {
t.Helper()
l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("free port: %v", err)
var lastErr error
for range 64 {
port := 19999 + int(fixturePortOffset.Add(1))
if port > 29999 {
t.Fatal("exhausted node fixture ports")
}
listener, err := net.Listen("tcp", ":"+strconv.Itoa(port))
if err != nil {
lastErr = err
continue
}
if err := listener.Close(); err != nil {
t.Fatalf("release fixture port %d: %v", port, err)
}
return port
}
defer l.Close()
return l.Addr().(*net.TCPAddr).Port
t.Fatalf("no available node fixture port: %v", lastErr)
return 0
}
func (p *panel) env() []string {