Fix bug where file is cached when io exception happens during data
transfer.