Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorfgsfds <4870330+fgsfds@users.noreply.github.com>2025-08-07 21:35:11 +0300
committerGitHub <noreply@github.com>2025-08-07 21:35:11 +0300
commitae08a29cde7f4125df0480712dcbff316573e787 (patch)
treec66c55ef0324807beffa2854a1da04cf84579122 /web
parent4f25eb230edd29fa7bcf8b9bcd02ec3c38cf0a2b (diff)
fix: Xray restarting after being manually stopped (#2896) (#3329)
Diffstat (limited to 'web')
-rw-r--r--web/html/index.html3
-rw-r--r--web/job/check_xray_running_job.go2
-rw-r--r--web/service/server.go1
-rw-r--r--web/service/xray.go37
4 files changed, 33 insertions, 10 deletions
diff --git a/web/html/index.html b/web/html/index.html
index d3155edd..42b8a032 100644
--- a/web/html/index.html
+++ b/web/html/index.html
@@ -169,9 +169,6 @@
<a-col>
<a-icon type="bars" :style="{ cursor: 'pointer', float: 'right' }" @click="openLogs()"></a-icon>
</a-col>
- <a-col>
- <a-icon type="bars" :style="{ cursor: 'pointer', float: 'right' }" @click="openXrayLogs()"></a-icon>
- </a-col>
</a-row>
</span>
<template slot="content">
diff --git a/web/job/check_xray_running_job.go b/web/job/check_xray_running_job.go
index bfef5ece..b28caf2b 100644
--- a/web/job/check_xray_running_job.go
+++ b/web/job/check_xray_running_job.go
@@ -16,7 +16,7 @@ func NewCheckXrayRunningJob() *CheckXrayRunningJob {
}
func (j *CheckXrayRunningJob) Run() {
- if j.xrayService.IsXrayRunning() {
+ if !j.xrayService.DidXrayCrash() {
j.checkTime = 0
} else {
j.checkTime++
diff --git a/web/service/server.go b/web/service/server.go
index 8b1bc0a9..6b4e5d63 100644
--- a/web/service/server.go
+++ b/web/service/server.go
@@ -347,7 +347,6 @@ func (s *ServerService) StopXrayService() error {
}
func (s *ServerService) RestartXrayService() error {
- s.xrayService.StopXray()
err := s.xrayService.RestartXray(true)
if err != nil {
logger.Error("start xray failed:", err)
diff --git a/web/service/xray.go b/web/service/xray.go
index 40de5305..f23ce9c4 100644
--- a/web/service/xray.go
+++ b/web/service/xray.go
@@ -3,6 +3,7 @@ package service
import (
"encoding/json"
"errors"
+ "runtime"
"sync"
"x-ui/logger"
@@ -14,7 +15,8 @@ import (
var (
p *xray.Process
lock sync.Mutex
- isNeedXrayRestart atomic.Bool
+ isNeedXrayRestart atomic.Bool // Indicates that restart was requested for Xray
+ isManuallyStopped atomic.Bool // Indicates that Xray was stopped manually from the panel
result string
)
@@ -32,7 +34,16 @@ func (s *XrayService) GetXrayErr() error {
if p == nil {
return nil
}
- return p.GetErr()
+
+ err := p.GetErr()
+
+ if runtime.GOOS == "windows" && err.Error() == "exit status 1" {
+ // exit status 1 on Windows means that Xray process was killed
+ // as we kill process to stop in on Windows, this is not an error
+ return nil
+ }
+
+ return err
}
func (s *XrayService) GetXrayResult() string {
@@ -45,7 +56,15 @@ func (s *XrayService) GetXrayResult() string {
if p == nil {
return ""
}
+
result = p.GetResult()
+
+ if runtime.GOOS == "windows" && result == "exit status 1" {
+ // exit status 1 on Windows means that Xray process was killed
+ // as we kill process to stop in on Windows, this is not an error
+ return ""
+ }
+
return result
}
@@ -184,7 +203,8 @@ func (s *XrayService) GetXrayTraffic() ([]*xray.Traffic, []*xray.ClientTraffic,
func (s *XrayService) RestartXray(isForce bool) error {
lock.Lock()
defer lock.Unlock()
- logger.Debug("restart xray, force:", isForce)
+ logger.Debug("restart Xray, force:", isForce)
+ isManuallyStopped.Store(false)
xrayConfig, err := s.GetXrayConfig()
if err != nil {
@@ -192,8 +212,8 @@ func (s *XrayService) RestartXray(isForce bool) error {
}
if s.IsXrayRunning() {
- if !isForce && p.GetConfig().Equals(xrayConfig) {
- logger.Debug("It does not need to restart xray")
+ if !isForce && p.GetConfig().Equals(xrayConfig) && !isNeedXrayRestart.Load() {
+ logger.Debug("It does not need to restart Xray")
return nil
}
p.Stop()
@@ -205,12 +225,14 @@ func (s *XrayService) RestartXray(isForce bool) error {
if err != nil {
return err
}
+
return nil
}
func (s *XrayService) StopXray() error {
lock.Lock()
defer lock.Unlock()
+ isManuallyStopped.Store(true)
logger.Debug("Attempting to stop Xray...")
if s.IsXrayRunning() {
return p.Stop()
@@ -225,3 +247,8 @@ func (s *XrayService) SetToNeedRestart() {
func (s *XrayService) IsNeedRestartAndSetFalse() bool {
return isNeedXrayRestart.CompareAndSwap(true, false)
}
+
+// Check if Xray is not running and wasn't stopped manually, i.e. crashed
+func (s *XrayService) DidXrayCrash() bool {
+ return !s.IsXrayRunning() && !isManuallyStopped.Load()
+}