make sure the stream ends