15050: Need to make sure to raise the semaphore when we're done
[arvados.git] / services / crunch-dispatch-local / crunch-dispatch-local.go
index 36d149272ff5de2989a0defe7dcd6ec5a9b92eab..62935447dd66643f8f76b6f8bf3a12c0c9b0c678 100644 (file)
@@ -153,7 +153,10 @@ func (lr *LocalRun) run(dispatcher *dispatch.Dispatcher,
                        return
                }
 
+               defer func() { <-lr.concurrencyLimit }()
+
                waitGroup.Add(1)
+               defer waitGroup.Done()
 
                cmd := exec.Command(*crunchRunCommand, uuid)
                cmd.Stdin = nil
@@ -207,7 +210,6 @@ func (lr *LocalRun) run(dispatcher *dispatch.Dispatcher,
                        delete(runningCmds, uuid)
                        runningCmdsMutex.Unlock()
                }
-               waitGroup.Done()
        }
 
        // If the container is not finalized, then change it to "Cancelled".