Fixed stream closing on error.