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

Commit 3307cba

Browse files
committed
Catch exceptions when sending GoAway frame
Implement stylistic changes to the warnin messages. Use a valid endpoint stream identifier for the unexpected stream id test. Catch any exception when sending the GoAway frame during graceful shutdown. We can only do our best to send the GoAway frame as specified in the spec.
1 parent 03d14b6 commit 3307cba

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

hyper/http20/connection.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,12 @@ def close(self):
246246
stream.close()
247247

248248
# Send GoAway frame to the server
249-
self._send_cb(GoAwayFrame(0), True)
249+
try:
250+
self._send_cb(GoAwayFrame(0), True)
251+
except:
252+
log.warn(
253+
"GoAway frame could not be sent: %s" % sys.exc_info()[0]
254+
)
250255

251256
if self._sock is not None:
252257
self._sock.close()
@@ -593,8 +598,9 @@ def _consume_frame_payload(self, frame, data):
593598
f = RstStreamFrame(frame.stream_id)
594599
f.error_code = 1 # PROTOCOL_ERROR
595600
self._send_cb(f)
596-
log.warning("Unexpected stream identifier %d" %
597-
(frame.stream_id))
601+
log.warning(
602+
"Unexpected stream identifier %d" % (frame.stream_id)
603+
)
598604
else:
599605
self.receive_frame(frame)
600606

test/test_hyper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,15 +1270,15 @@ def data_callback(frame):
12701270
c = HTTP20Connection('www.google.com')
12711271
c._send_cb = data_callback
12721272

1273-
f = DataFrame(-1)
1273+
f = DataFrame(2)
12741274
data = memoryview(b"hi there sir")
12751275
c._consume_frame_payload(f, data)
12761276

12771277
# If we receive an unexpected stream id then we cancel the stream
12781278
# by sending a reset stream that contains the protocol error code (1)
12791279
f = frames[0]
12801280
assert len(frames) == 1
1281-
assert f.stream_id == -1
1281+
assert f.stream_id == 2
12821282
assert isinstance(f, RstStreamFrame)
12831283
assert f.error_code == 1 # PROTOCOL_ERROR
12841284

0 commit comments

Comments
 (0)