mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-16 18:15:01 +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:
@@ -2,7 +2,6 @@ package service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@@ -78,6 +77,9 @@ func currentXrayProcess() *xray.Process {
|
||||
return process
|
||||
}
|
||||
|
||||
// ErrXrayNotRunning reports an operation that requires a running core when xray is stopped.
|
||||
var ErrXrayNotRunning = xray.ErrXrayNotRunning
|
||||
|
||||
// XrayService provides business logic for Xray process management.
|
||||
// It handles starting, stopping, restarting Xray, and managing its configuration.
|
||||
type XrayService struct {
|
||||
@@ -1245,7 +1247,7 @@ func stripDisabledRules(routerCfg json_util.RawMessage) json_util.RawMessage {
|
||||
func (s *XrayService) GetXrayTraffic() ([]*xray.Traffic, []*xray.ClientTraffic, error) {
|
||||
process := currentXrayProcess()
|
||||
if process == nil || !process.IsRunning() {
|
||||
err := errors.New("xray is not running")
|
||||
err := ErrXrayNotRunning
|
||||
logger.Debug("Attempted to fetch Xray traffic, but Xray is not running:", err)
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -1355,7 +1357,7 @@ func (s *XrayService) OverrideBalancer(tag, target string) error {
|
||||
defer lock.Unlock()
|
||||
process := currentXrayProcess()
|
||||
if process == nil || !process.IsRunning() {
|
||||
return errors.New("xray is not running")
|
||||
return ErrXrayNotRunning
|
||||
}
|
||||
if err := s.xrayAPI.Init(process.GetAPIPort()); err != nil {
|
||||
return err
|
||||
@@ -1369,7 +1371,7 @@ func (s *XrayService) OverrideBalancer(tag, target string) error {
|
||||
func (s *XrayService) TestRoute(req xray.RouteTestRequest) (*xray.RouteTestResult, error) {
|
||||
process := currentXrayProcess()
|
||||
if process == nil || !process.IsRunning() {
|
||||
return nil, errors.New("xray is not running")
|
||||
return nil, ErrXrayNotRunning
|
||||
}
|
||||
if err := s.xrayAPI.Init(process.GetAPIPort()); err != nil {
|
||||
return nil, err
|
||||
@@ -1611,7 +1613,7 @@ func (s *XrayService) StopXray() error {
|
||||
if process != nil && process.IsRunning() {
|
||||
return process.Stop()
|
||||
}
|
||||
return errors.New("xray is not running")
|
||||
return ErrXrayNotRunning
|
||||
}
|
||||
|
||||
// SetToNeedRestart marks that Xray needs to be restarted.
|
||||
|
||||
Reference in New Issue
Block a user