Skip to content

Commit

Permalink
Merge pull request #2852 from hashicorp/b-gc-race
Browse files Browse the repository at this point in the history
Fix deadlock caused by syncing during destroy
  • Loading branch information
schmichael authored Jul 18, 2017
2 parents e3a6b5b + 8c4b760 commit 2a44ecf
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion client/alloc_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,19 @@ func (r *AllocRunner) destroyTaskRunners(destroyEvent *structs.TaskEvent) {
func (r *AllocRunner) handleDestroy() {
// Final state sync. We do this to ensure that the server has the correct
// state as we wait for a destroy.
r.syncStatus()
alloc := r.Alloc()

//TODO(schmichael) updater can cause a GC which can block on this alloc
// runner shutting down. Since handleDestroy can be called by Run() we
// can't block shutdown here as it would cause a deadlock.
go r.updater(alloc)

// Broadcast and persist state synchronously
r.allocBroadcast.Send(alloc)
if err := r.saveAllocRunnerState(); err != nil {
r.logger.Printf("[WARN] client: alloc %q unable to persist state but should be GC'd soon anyway:%v",
r.allocID, err)
}

for {
select {
Expand Down

0 comments on commit 2a44ecf

Please sign in to comment.