Merge pull request #1665 from shenghuang147/add_core_startup_timeout_param

feat: Add core startup timeout parameter and terminate timed-out processes
This commit is contained in:
Markson Hon authored and GitHub committed 2025-10-05 12:24:36 +08:00
commit ed37e3a5ca
2 files changed
+10 -1

No files matched your search

+5
View File
@@ -19,6 +19,7 @@ type Params struct {
Config string `id:"config" short:"c" desc:"v2rayA configuration directory"`
V2rayConfigDirectory string `id:"v2ray-confdir" desc:"Additional v2ray config directory, files in it will be combined with config generated by v2rayA"`
V2rayAssetsDirectory string `id:"v2ray-assetsdir" desc:"v2ray-core assets directory for searching and downloading files like geoip.dat. This will override environment V2RAY_LOCATION_ASSET and XRAY_LOCATION_ASSET."`
CoreStartupTimeout int64 `id:"core-startup-timeout" default:"15" desc:"Timeout duration in seconds for starting v2ray or xray core. On devices with lower performance, consider increasing this value."`
TransparentHook string `id:"transparent-hook" desc:"the executable file to run in the transparent proxy life-cycle. v2rayA will pass in the --transparent-type (tproxy, redirect) and --stage (pre-start, post-start, pre-stop, post-stop) arguments."`
CoreHook string `id:"core-hook" desc:"the executable file to run in the v2ray-core life-cycle. v2rayA will pass in the --stage (pre-start, post-start, pre-stop, post-stop) argument."`
PluginManager string `id:"plugin-manager" desc:"the executable file to run in the v2ray-core life-cycle. v2rayA will pass in the --stage (pre-start, post-start, pre-stop, post-stop) argument."`
@@ -104,6 +105,10 @@ func initFunc() {
log.Fatal("failed to set V2rayAssetsDirectory: %v", err)
}
}
if params.CoreStartupTimeout <= 0 {
log.Fatal("invalid CoreStartupTimeout: %d seconds. It must be a positive integer greater than 0.", params.CoreStartupTimeout)
}
}
var once sync.Once
+5 -1
View File
@@ -18,6 +18,7 @@ import (
"strconv"
"strings"
"sync"
"syscall"
"time"
)
@@ -138,6 +139,7 @@ func NewProcess(tmpl *Template,
}
log.Trace("portList for connectivity test: %+v", portList)
startTime := time.Now()
startTimeOut := time.Duration(conf.GetEnvironmentConfig().CoreStartupTimeout) * time.Second
for i := 0; i < len(portList); {
conn, err := net.Dial("tcp", net.JoinHostPort("127.0.0.1", portList[i]))
if err == nil {
@@ -151,7 +153,9 @@ func NewProcess(tmpl *Template,
}
return nil, fmt.Errorf("unexpected exiting: check the log for more information")
}
if time.Since(startTime) > 30*time.Second {
if time.Since(startTime) > startTimeOut {
log.Info("Attempting to terminate timed-out process with SIGTERM")
_ = proc.Signal(syscall.SIGTERM)
return nil, fmt.Errorf("timeout: check the log for more information")
}
time.Sleep(100 * time.Millisecond)