mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-18 19:15:03 +03:00
fix(web): stop clean shutdowns logging false errors, and let the panel stop its children (#6884)
A systemd stop or restart logged "Server shutdown failed: use of closed network connection | xray is not running" on every clean exit. httpServer.Shutdown already closes the listener, so the second Close's net.ErrClosed is now ignored, and StopXray's not-running case is a sentinel (ErrXrayNotRunning) that Stop treats as done. The shipped units now use KillMode=mixed, so SIGTERM reaches only the panel, which stops Xray and the sidecars itself; systemd still SIGKILLs whatever is left after the stop timeout.
This commit is contained in:
@@ -227,6 +227,8 @@ var (
|
||||
xrayVersionTimeout = 5 * time.Second
|
||||
// OnCrash is called when xray crashes unexpectedly. Set from web layer.
|
||||
OnCrash func(err error)
|
||||
// ErrXrayNotRunning reports an operation that requires a running core when xray is stopped.
|
||||
ErrXrayNotRunning = errors.New("xray is not running")
|
||||
)
|
||||
|
||||
// newProcess creates a new internal process struct for Xray.
|
||||
@@ -758,7 +760,7 @@ func (p *process) waitForCommand(cmd *exec.Cmd, done chan struct{}) {
|
||||
// Stop terminates the running Xray process.
|
||||
func (p *process) Stop() error {
|
||||
if !p.IsRunning() {
|
||||
return errors.New("xray is not running")
|
||||
return ErrXrayNotRunning
|
||||
}
|
||||
p.intentionalStop.Store(true)
|
||||
|
||||
@@ -768,7 +770,7 @@ func (p *process) Stop() error {
|
||||
cmd := p.cmd
|
||||
p.mu.RUnlock()
|
||||
if cmd == nil || cmd.Process == nil {
|
||||
return errors.New("xray is not running")
|
||||
return ErrXrayNotRunning
|
||||
}
|
||||
|
||||
// Remove temporary config file used for test runs so main config is never touched
|
||||
|
||||
@@ -96,6 +96,15 @@ func TestIntentionalStopDoesNotRecordExitError(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStopWhenNotRunningReturnsErrXrayNotRunning(t *testing.T) {
|
||||
initProcessTestLogger(t)
|
||||
|
||||
p := NewProcess(&Config{})
|
||||
if err := p.Stop(); !errors.Is(err, ErrXrayNotRunning) {
|
||||
t.Fatalf("Stop() on unstarted process err = %v, want ErrXrayNotRunning", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStopKillsProcessThatIgnoresSIGTERM(t *testing.T) {
|
||||
initProcessTestLogger(t)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user