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