mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-16 06:52:21 +08:00
Fix cancel on start
This commit is contained in:
parent
d1fe17a4db
commit
4a6ab5e9fd
|
@ -69,6 +69,20 @@ func create() (*box.Box, context.CancelFunc, error) {
|
||||||
cancel()
|
cancel()
|
||||||
return nil, nil, E.Cause(err, "create service")
|
return nil, nil, E.Cause(err, "create service")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
osSignals := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(osSignals, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
|
||||||
|
defer func() {
|
||||||
|
signal.Stop(osSignals)
|
||||||
|
close(osSignals)
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
_, loaded := <-osSignals
|
||||||
|
if loaded {
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
|
}()
|
||||||
err = instance.Start()
|
err = instance.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cancel()
|
cancel()
|
||||||
|
@ -80,6 +94,7 @@ func create() (*box.Box, context.CancelFunc, error) {
|
||||||
func run() error {
|
func run() error {
|
||||||
osSignals := make(chan os.Signal, 1)
|
osSignals := make(chan os.Signal, 1)
|
||||||
signal.Notify(osSignals, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
|
signal.Notify(osSignals, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
|
||||||
|
defer signal.Stop(osSignals)
|
||||||
for {
|
for {
|
||||||
instance, cancel, err := create()
|
instance, cancel, err := create()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user