Automatically sleep and retry on a lock error

This uses basic exponential backoff. I'm not sure if that's really needed, but
it does.

Fixes #670

<!---
@huboard:{"order":465.59375,"custom_state":""}
-->