End a stream on error to prevent too many open files.