Waits properly for all subprocess to exit
This commit is contained in:
@@ -110,9 +110,7 @@ func (l *looper) Run(ctx context.Context, restart <-chan struct{}, wg *sync.Wait
|
||||
waitError := make(chan error)
|
||||
go func() {
|
||||
err := waitFn() // blocking
|
||||
if unboundCtx.Err() != context.Canceled {
|
||||
waitError <- err
|
||||
}
|
||||
waitError <- err
|
||||
}()
|
||||
|
||||
// Wait for one of the three cases below
|
||||
@@ -120,6 +118,7 @@ func (l *looper) Run(ctx context.Context, restart <-chan struct{}, wg *sync.Wait
|
||||
case <-ctx.Done():
|
||||
l.logger.Warn("context canceled: exiting loop")
|
||||
unboundCancel()
|
||||
<-waitError
|
||||
close(waitError)
|
||||
return
|
||||
case <-restart: // triggered restart
|
||||
|
||||
@@ -62,14 +62,13 @@ func (l *looper) Run(ctx context.Context, restart <-chan struct{}, wg *sync.Wait
|
||||
waitError := make(chan error)
|
||||
go func() {
|
||||
err := waitFn() // blocking
|
||||
if openvpnCtx.Err() != context.Canceled {
|
||||
waitError <- err
|
||||
}
|
||||
waitError <- err
|
||||
}()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
l.logger.Warn("context canceled: exiting loop")
|
||||
openvpnCancel()
|
||||
<-waitError
|
||||
close(waitError)
|
||||
return
|
||||
case <-restart: // triggered restart
|
||||
|
||||
@@ -90,14 +90,13 @@ func (l *looper) Run(ctx context.Context, restart <-chan struct{}, wg *sync.Wait
|
||||
waitError := make(chan error)
|
||||
go func() {
|
||||
err := waitFn() // blocking
|
||||
if shadowsocksCtx.Err() != context.Canceled {
|
||||
waitError <- err
|
||||
}
|
||||
waitError <- err
|
||||
}()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
l.logger.Warn("context canceled: exiting loop")
|
||||
shadowsocksCancel()
|
||||
<-waitError
|
||||
close(waitError)
|
||||
return
|
||||
case <-restart: // triggered restart
|
||||
|
||||
@@ -82,14 +82,13 @@ func (l *looper) Run(ctx context.Context, restart <-chan struct{}, wg *sync.Wait
|
||||
waitError := make(chan error)
|
||||
go func() {
|
||||
err := waitFn() // blocking
|
||||
if tinyproxyCtx.Err() != context.Canceled {
|
||||
waitError <- err
|
||||
}
|
||||
waitError <- err
|
||||
}()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
l.logger.Warn("context canceled: exiting loop")
|
||||
tinyproxyCancel()
|
||||
<-waitError
|
||||
close(waitError)
|
||||
return
|
||||
case <-restart: // triggered restart
|
||||
|
||||
Reference in New Issue
Block a user