Change to Stop State in case of an error occure. fix connection bug
This commit is contained in:
@@ -122,6 +122,7 @@ func generateConfigFromFile(path string, configOpt config.ConfigOptions) (string
|
||||
func start(configPath *C.char, disableMemoryLimit bool) (CErr *C.char) {
|
||||
defer config.DeferPanicToError("start", func(err error) {
|
||||
CErr = C.CString(err.Error())
|
||||
stopAndAlert("Unexpected Error!", err)
|
||||
})
|
||||
|
||||
if status != Stopped {
|
||||
@@ -153,7 +154,7 @@ func startService(delayStart bool) error {
|
||||
var patchedOptions *option.Options
|
||||
patchedOptions, err = config.BuildConfig(*configOptions, options)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error building config: %w", err)
|
||||
return stopAndAlert("Error Building Config", err)
|
||||
}
|
||||
|
||||
config.SaveCurrentConfig(filepath.Join(sWorkingPath, "current-config.json"), *patchedOptions)
|
||||
@@ -219,6 +220,7 @@ func stop() (CErr *C.char) {
|
||||
func restart(configPath *C.char, disableMemoryLimit bool) (CErr *C.char) {
|
||||
defer config.DeferPanicToError("restart", func(err error) {
|
||||
CErr = C.CString(err.Error())
|
||||
stopAndAlert("Unexpected Error!", err)
|
||||
})
|
||||
log.Debug("[Service] Restarting")
|
||||
|
||||
|
||||
@@ -24,7 +24,13 @@ func propagateStatus(newStatus string) {
|
||||
bridge.SendStringToPort(statusPropagationPort, string(msg))
|
||||
}
|
||||
|
||||
func stopAndAlert(alert string, err error) error {
|
||||
func stopAndAlert(alert string, err error) (resultErr error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
resultErr = fmt.Errorf("panic recovered: %v", r)
|
||||
}
|
||||
}()
|
||||
|
||||
status = Stopped
|
||||
message := err.Error()
|
||||
fmt.Printf("Error: %s: %v\n", alert, err)
|
||||
|
||||
3
go.mod
3
go.mod
@@ -19,6 +19,7 @@ require (
|
||||
require (
|
||||
berty.tech/go-libtor v1.0.385 // indirect
|
||||
github.com/ajg/form v1.5.1 // indirect
|
||||
github.com/akavel/rsrc v0.10.2 // indirect
|
||||
github.com/andybalholm/brotli v1.0.6 // indirect
|
||||
github.com/caddyserver/certmagic v0.20.0 // indirect
|
||||
github.com/cloudflare/circl v1.3.7 // indirect
|
||||
@@ -103,7 +104,7 @@ require (
|
||||
lukechampine.com/blake3 v1.2.1 // indirect
|
||||
)
|
||||
|
||||
replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.7.9-0.20240205192750-1f788a879120
|
||||
replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.7.9-0.20240206093618-6b04f360fe5a
|
||||
|
||||
replace github.com/sagernet/wireguard-go => github.com/hiddify/wireguard-go v0.0.0-20240125143346-481d18d77fe1
|
||||
|
||||
|
||||
6
go.sum
6
go.sum
@@ -2,6 +2,8 @@ berty.tech/go-libtor v1.0.385 h1:RWK94C3hZj6Z2GdvePpHJLnWYobFr3bY/OdUJ5aoEXw=
|
||||
berty.tech/go-libtor v1.0.385/go.mod h1:9swOOQVb+kmvuAlsgWUK/4c52pm69AdbJsxLzk+fJEw=
|
||||
github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU=
|
||||
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
|
||||
github.com/akavel/rsrc v0.10.2 h1:Zxm8V5eI1hW4gGaYsJQUhxpjkENuG91ki8B4zCrvEsw=
|
||||
github.com/akavel/rsrc v0.10.2/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
|
||||
github.com/andybalholm/brotli v1.0.6 h1:Yf9fFpf49Zrxb9NlQaluyE92/+X7UVHlhMNJN2sxfOI=
|
||||
github.com/andybalholm/brotli v1.0.6/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/caddyserver/certmagic v0.20.0 h1:bTw7LcEZAh9ucYCRXyCpIrSAGplplI0vGYJ4BpCQ/Fc=
|
||||
@@ -51,8 +53,8 @@ github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE
|
||||
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
|
||||
github.com/hiddify-com/wireguard-go v0.0.2-alpha.0.20240205205805-4eae577551e2 h1:yoQz+Bp6fqebC/w7KcPV++mLq6xxfbulHtdJGF3KZE4=
|
||||
github.com/hiddify-com/wireguard-go v0.0.2-alpha.0.20240205205805-4eae577551e2/go.mod h1:Cgjuqx41IFI/FquERk3i5DyAidsA3KD+rbdOWbY1HgY=
|
||||
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240205192750-1f788a879120 h1:+O6KnUbbGp8rq2NygF2DllAsmPymqQLssLdsjczzbWI=
|
||||
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240205192750-1f788a879120/go.mod h1:HaSsaDUdxYL0tYUPx45asbyH9dIIOUHUinQJuZbS5pE=
|
||||
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240206093618-6b04f360fe5a h1:c09W2YBtDhAT+8qa3hdH86PpVGAI6vESrNg4ZwXa2U8=
|
||||
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240206093618-6b04f360fe5a/go.mod h1:HaSsaDUdxYL0tYUPx45asbyH9dIIOUHUinQJuZbS5pE=
|
||||
github.com/hiddify/ray2sing v0.0.0-20240130210008-8975ff77e3cd h1:3fKPvAWXTMGY0Qsk6wjCamIeC4xbrOUShMY95G5AZN4=
|
||||
github.com/hiddify/ray2sing v0.0.0-20240130210008-8975ff77e3cd/go.mod h1:zYKnf7EoPqrk7JOMO9BApTXxfH0sva8AKfoFywN7uuA=
|
||||
github.com/hiddify/wireguard-go v0.0.0-20240125143346-481d18d77fe1 h1:neOb+wzHbWLNZ2sHFEV4+GTuqORO7/MndQLFW8FjUY8=
|
||||
|
||||
Reference in New Issue
Block a user