From 38aafc0f83c4385af72250371c8e065956ec328d Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Fri, 3 Jun 2016 11:53:43 -0700 Subject: [PATCH] Fix case in periodic dispatch and blocked evals where lock was not released --- nomad/blocked_evals.go | 1 + nomad/periodic.go | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/nomad/blocked_evals.go b/nomad/blocked_evals.go index 3a49c964276d..52ee829f1159 100644 --- a/nomad/blocked_evals.go +++ b/nomad/blocked_evals.go @@ -106,6 +106,7 @@ func (b *BlockedEvals) SetEnabled(enabled bool) { b.l.Lock() if b.enabled == enabled { // No-op + b.l.Unlock() return } else if enabled { go b.watchCapacity() diff --git a/nomad/periodic.go b/nomad/periodic.go index 97e1b24523f0..09dadfdff35a 100644 --- a/nomad/periodic.go +++ b/nomad/periodic.go @@ -81,7 +81,11 @@ func (s *Server) DispatchJob(job *structs.Job) (*structs.Evaluation, error) { // RunningChildren checks whether the passed job has any running children. func (s *Server) RunningChildren(job *structs.Job) (bool, error) { - state := s.fsm.State() + state, err := s.fsm.State().Snapshot() + if err != nil { + return false, err + } + prefix := fmt.Sprintf("%s%s", job.ID, structs.PeriodicLaunchSuffix) iter, err := state.JobsByIDPrefix(prefix) if err != nil { @@ -272,11 +276,13 @@ func (p *PeriodicDispatch) ForceRun(jobID string) (*structs.Evaluation, error) { // Do nothing if not enabled if !p.enabled { + p.l.Unlock() return nil, fmt.Errorf("periodic dispatch disabled") } job, tracked := p.tracked[jobID] if !tracked { + p.l.Unlock() return nil, fmt.Errorf("can't force run non-tracked job %v", jobID) }