Buildkite-agent lock: what happens on failure

I was looking at the new buildkite-agent lock feature: what happens if a job acquires a lock, but fails before the lock is released? Does it get automatically released?

Also how does locking work: it states that the only scope currently supported is “machine”: what does this mean?

Hey @simonbyrne :wave:

Great questions!

In the event the job acquires a lock, but fails or is cancelled before the lock is released, then the lock will never be removed on the instance running that agent.

Some options you could use to handle this would be:

  • Add some logic in the pre-exit hook on your agent, which would release the lock under some conditions (maybe if the command status is non-zero), etc.
  • Configure your jobs to timeout after a certain time - that way you won’t have jobs sitting waiting to acquire a lock forever until

The current scope of machine refers to the instance running the agent.

The lock is acquired by the process being run by the agent’s job command, so other agents running on the same instance wouldn’t be able to execute on the same.

Hopefully that helps, but please let us know if you have any other questions!

Thank you. The reason I was interested was that we have multiple machines connected using a shared file system, and I was hoping to use a lock to control access to certain directories. It sounds like that isn’t possible yet.

Having some mechanism that automatically releases any locks would also be somewhat helpful.

That’s understandable! My suggestion in this case would be to head over to the agent repo and open up an issue, as we appreciate the feedback!