Reintroduce an optimisation lost in some cut and paste. The cache lock is removed as soon as we see an EOS, or is removed immediately if a failure has occurred.
Changed paths: