diff --git a/client/client.go b/client/client.go index 80c3e81a3..18fbb4ae8 100644 --- a/client/client.go +++ b/client/client.go @@ -1759,6 +1759,9 @@ func (c *Client) removeAlloc(alloc *structs.Allocation) error { delete(c.allocs, alloc.ID) c.allocLock.Unlock() + // Remove the allocrunner from garbage collector + c.garbageCollector.Remove(ar) + ar.Destroy() return nil } diff --git a/client/gc.go b/client/gc.go index 9d9c4b43a..0e41d0950 100644 --- a/client/gc.go +++ b/client/gc.go @@ -329,3 +329,15 @@ func (a *AllocGarbageCollector) MarkForCollection(ar *AllocRunner) error { a.logger.Printf("[INFO] client: marking allocation %v for GC", ar.Alloc().ID) return a.allocRunners.Push(ar) } + +// Remove removes an alloc runner without garbage collecting it +func (a *AllocGarbageCollector) Remove(ar *AllocRunner) { + if ar == nil || ar.Alloc() == nil { + return + } + + alloc := ar.Alloc() + if _, err := a.allocRunners.Remove(alloc.ID); err == nil { + a.logger.Printf("[INFO] client: removed alloc runner %v from garbage collector", alloc.ID) + } +}