Fix to avoid crashes after the stream closes up.