Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit 53a4001

Browse files
committed
Tolerate failed RST_STREAM attempts when closing streams.
1 parent 3bea1c9 commit 53a4001

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

hyper/http20/stream.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
Each stream is identified by a monotonically increasing integer, assigned to
1414
the stream by the endpoint that initiated the stream.
1515
"""
16+
import h2.exceptions
17+
1618
from ..common.headers import HTTPHeaderMap
1719
from .util import h2_safe_headers
1820
import logging
@@ -275,8 +277,16 @@ def close(self, error_code=None):
275277
"""
276278
# FIXME: I think this is overbroad, but for now it's probably ok.
277279
if not (self.remote_closed and self.local_closed):
278-
self._conn.reset_stream(self.stream_id, error_code or 0)
279-
self._send_cb(self._conn.data_to_send())
280+
try:
281+
self._conn.reset_stream(self.stream_id, error_code or 0)
282+
except h2.exceptions.ProtocolError:
283+
# If for any reason we can't reset the stream, just tolerate
284+
# it.
285+
pass
286+
else:
287+
self._send_cb(
288+
self._conn.data_to_send(), tolerate_peer_gone=True
289+
)
280290
self.remote_closed = True
281291
self.local_closed = True
282292

0 commit comments

Comments
 (0)