When beginwrite fails the function sleeps for 1000ms and retries the operation until successful.