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

Commit 6531ae9

Browse files
author
Tim Emiola
committed
Modify how stream resets are reported.
Fixes #147 Make the Stream when the stream is next accessed rather than immediately the data is read. This should avoid some errors that might occur when there are multiple concurrent readers.
1 parent 5704d26 commit 6531ae9

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

hyper/http20/connection.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from .stream import Stream
2020
from .response import HTTP20Response, HTTP20Push
2121
from .window import FlowControlManager
22-
from .exceptions import ConnectionError
22+
from .exceptions import ConnectionError, StreamResetError
2323
from . import errors
2424

2525
import errno
@@ -186,8 +186,12 @@ def request(self, method, url, body=None, headers=None):
186186
return stream_id
187187

188188
def _get_stream(self, stream_id):
189-
return (self.streams[stream_id] if stream_id is not None
190-
else self.recent_stream)
189+
if stream_id is None:
190+
return self.recent_stream
191+
elif stream_id in self.reset_streams or stream_id not in self.streams:
192+
raise StreamResetError("Stream forcefully closed")
193+
else:
194+
return self.streams[stream_id]
191195

192196
def get_response(self, stream_id=None):
193197
"""

hyper/http20/stream.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
the stream by the endpoint that initiated the stream.
1515
"""
1616
from ..common.headers import HTTPHeaderMap
17-
from .exceptions import StreamResetError
1817
from .util import h2_safe_headers
1918
import logging
2019

@@ -201,7 +200,7 @@ def receive_reset(self, event):
201200
Stream forcefully reset.
202201
"""
203202
self.remote_closed = True
204-
raise StreamResetError("Stream forcefully closed")
203+
self._close_cb(self.stream_id)
205204

206205
def get_headers(self):
207206
"""

test/test_integration.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ def socket_handler(listener):
678678
conn._recv_cb()
679679

680680
# However, attempting to get the response should.
681-
with pytest.raises(KeyError):
681+
with pytest.raises(StreamResetError):
682682
conn.get_response(stream_id)
683683

684684
# Awesome, we're done now.
@@ -716,14 +716,14 @@ def socket_handler(listener):
716716
conn = self.get_connection()
717717
conn.request('GET', '/')
718718

719-
# Now, eat the RstStream frames. The first one throws a
720-
# StreamResetError.
721-
with pytest.raises(StreamResetError):
722-
conn._single_read()
723-
724-
# The next should throw no exception.
719+
# Now, eat the Rst frames. These should not cause an exception.
720+
conn._single_read()
725721
conn._single_read()
726722

723+
# However, attempting to get the response should.
724+
with pytest.raises(StreamResetError):
725+
conn.get_response(1)
726+
727727
assert conn.reset_streams == set([1])
728728

729729
# Awesome, we're done now.

0 commit comments

Comments
 (0)