Maintenance: prevent exit race condition for loops
This commit is contained in:
@@ -159,6 +159,11 @@ func (l *looper) Run(ctx context.Context, done chan<- struct{}) {
|
|||||||
stayHere = false
|
stayHere = false
|
||||||
case err := <-waitError: // unexpected error
|
case err := <-waitError: // unexpected error
|
||||||
unboundCancel()
|
unboundCancel()
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
close(waitError)
|
||||||
|
closeStreams()
|
||||||
|
return
|
||||||
|
}
|
||||||
l.state.setStatusWithLock(constants.Crashed)
|
l.state.setStatusWithLock(constants.Crashed)
|
||||||
const fallback = true
|
const fallback = true
|
||||||
l.useUnencryptedDNS(fallback)
|
l.useUnencryptedDNS(fallback)
|
||||||
|
|||||||
@@ -211,6 +211,14 @@ func (l *looper) Run(ctx context.Context, done chan<- struct{}) { //nolint:gocog
|
|||||||
stayHere = false
|
stayHere = false
|
||||||
case err := <-waitError: // unexpected error
|
case err := <-waitError: // unexpected error
|
||||||
openvpnCancel()
|
openvpnCancel()
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
close(waitError)
|
||||||
|
close(stdoutLines)
|
||||||
|
close(stderrLines)
|
||||||
|
<-lineCollectionDone
|
||||||
|
<-portForwardDone
|
||||||
|
return
|
||||||
|
}
|
||||||
l.state.setStatusWithLock(constants.Crashed)
|
l.state.setStatusWithLock(constants.Crashed)
|
||||||
l.logAndWait(ctx, err)
|
l.logAndWait(ctx, err)
|
||||||
l.crashed = true
|
l.crashed = true
|
||||||
|
|||||||
@@ -139,6 +139,9 @@ func (l *looper) Run(ctx context.Context, done chan<- struct{}) {
|
|||||||
case err := <-waitError: // unexpected error
|
case err := <-waitError: // unexpected error
|
||||||
shadowsocksCancel()
|
shadowsocksCancel()
|
||||||
close(waitError)
|
close(waitError)
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
l.state.setStatusWithLock(constants.Crashed)
|
l.state.setStatusWithLock(constants.Crashed)
|
||||||
l.logAndWait(ctx, err)
|
l.logAndWait(ctx, err)
|
||||||
crashed = true
|
crashed = true
|
||||||
|
|||||||
Reference in New Issue
Block a user