Well, this is a much better fix.

In the event that the db is locked, let's rollback things and reset things to be on the safe side. Much better fix than sleep.