From 46de886b53f0519d45d011090ac8eacc921d1134 Mon Sep 17 00:00:00 2001 From: mhsanaei Date: Sun, 14 Sep 2025 20:04:12 +0200 Subject: [PATCH] windows: error filter --- xray/log_writer.go | 7 +++++++ xray/process.go | 12 +++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/xray/log_writer.go b/xray/log_writer.go index b6e04db7..d91ace3b 100644 --- a/xray/log_writer.go +++ b/xray/log_writer.go @@ -2,6 +2,7 @@ package xray import ( "regexp" + "runtime" "strings" "x-ui/logger" @@ -20,6 +21,12 @@ func (lw *LogWriter) Write(m []byte) (n int, err error) { // Convert the data to a string message := strings.TrimSpace(string(m)) + msgLowerAll := strings.ToLower(message) + + // Suppress noisy Windows process-kill signal that surfaces as exit status 1 + if runtime.GOOS == "windows" && strings.Contains(msgLowerAll, "exit status 1") { + return len(m), nil + } // Check if the message contains a crash if crashRegex.MatchString(message) { diff --git a/xray/process.go b/xray/process.go index 21ca5223..319f96d0 100644 --- a/xray/process.go +++ b/xray/process.go @@ -9,6 +9,7 @@ import ( "os" "os/exec" "runtime" + "strings" "syscall" "time" @@ -224,6 +225,15 @@ func (p *process) Start() (err error) { go func() { err := cmd.Run() if err != nil { + // On Windows, killing the process results in "exit status 1" which isn't an error for us + if runtime.GOOS == "windows" { + errStr := strings.ToLower(err.Error()) + if strings.Contains(errStr, "exit status 1") { + // Suppress noisy log on graceful stop + p.exitErr = err + return + } + } logger.Error("Failure in running xray-core:", err) p.exitErr = err } @@ -239,7 +249,7 @@ func (p *process) Stop() error { if !p.IsRunning() { return errors.New("xray is not running") } - + if runtime.GOOS == "windows" { return p.cmd.Process.Kill() } else {