script: Add some workarounds for image cache task races