Deal with race condition when generating thumbnails