The logic simply consists of retrying for as long as the library says the data is locked, but it eventually gets through.