Fix a panic on shutdown (#2050)

Last-minute events coming through the engine could cause the goroutine
iterating over engineEvents to write to displayEvents after it has
already been closed by the main goroutine.
This commit is contained in:
Sean Gillespie 2018-10-12 10:29:47 -07:00 committed by GitHub
parent 8c230e9caa
commit dfdb10393a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View file

@ -342,12 +342,12 @@ func (b *localBackend) apply(ctx context.Context, kind apitype.UpdateKind, stack
<-displayDone
scope.Close() // Don't take any cancellations anymore, we're shutting down.
close(engineEvents)
close(displayEvents)
close(displayDone)
contract.IgnoreClose(manager)
// Make sure the goroutine writing to displayEvents and events has exited before proceeding.
<-eventsDone
close(displayEvents)
// Save update results.
result := backend.SucceededResult

View file

@ -828,13 +828,13 @@ func (b *cloudBackend) runEngineAction(
<-displayDone
scope.Close() // Don't take any cancellations anymore, we're shutting down.
close(engineEvents)
close(displayEvents)
close(displayDone)
contract.IgnoreClose(manager)
// Make sure that the goroutine writing to displayEvents and callerEventsOpt
// has exited before proceeding
<-eventsDone
close(displayEvents)
status := apitype.UpdateStatusSucceeded
if err != nil {