Maintenance: prevent exit race condition for loops

This commit is contained in:
Quentin McGaw (desktop)
2021-06-10 14:13:08 +00:00
parent fb7fdcd925
commit 05c6b9379a
3 changed files with 16 additions and 0 deletions

View File

@@ -211,6 +211,14 @@ func (l *looper) Run(ctx context.Context, done chan<- struct{}) { //nolint:gocog
stayHere = false
case err := <-waitError: // unexpected error
openvpnCancel()
if ctx.Err() != nil {
close(waitError)
close(stdoutLines)
close(stderrLines)
<-lineCollectionDone
<-portForwardDone
return
}
l.state.setStatusWithLock(constants.Crashed)
l.logAndWait(ctx, err)
l.crashed = true