fix corner case when Stream.close() is called multiple times