diff --git a/client/alloc_runner.go b/client/alloc_runner.go index 6275bd1dd5a..331ddd752d7 100644 --- a/client/alloc_runner.go +++ b/client/alloc_runner.go @@ -425,18 +425,8 @@ func copyTaskStates(states map[string]*structs.TaskState) map[string]*structs.Ta func (r *AllocRunner) Alloc() *structs.Allocation { r.allocLock.Lock() - // Clear the job before copying - job := r.alloc.Job - - // Since we are clearing the job, anything that access the alloc.Job field - // must acquire the lock or access it via this method. - r.alloc.Job = nil - - alloc := r.alloc.Copy() - - // Restore - r.alloc.Job = job - alloc.Job = job + // Don't do a deep copy of the job + alloc := r.alloc.CopySkipJob() // The status has explicitly been set. if r.allocClientStatus != "" || r.allocClientDescription != "" { @@ -774,7 +764,7 @@ func (r *AllocRunner) handleDestroy() { return case <-r.updateCh: - r.logger.Printf("[ERR] client: dropping update to terminal alloc '%s'", r.alloc.ID) + r.logger.Printf("[DEBUG] client: dropping update to terminal alloc '%s'", r.alloc.ID) } } } diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 3ff464360ce..43c9a98fd28 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -3680,13 +3680,25 @@ type Allocation struct { } func (a *Allocation) Copy() *Allocation { + return a.copyImpl(true) +} + +// Copy provides a copy of the allocation but doesn't deep copy the job +func (a *Allocation) CopySkipJob() *Allocation { + return a.copyImpl(false) +} + +func (a *Allocation) copyImpl(job bool) *Allocation { if a == nil { return nil } na := new(Allocation) *na = *a - na.Job = na.Job.Copy() + if job { + na.Job = na.Job.Copy() + } + na.Resources = na.Resources.Copy() na.SharedResources = na.SharedResources.Copy()