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

Commit

Permalink
Merge pull request #261 from Lukasa/issue/260
Browse files Browse the repository at this point in the history
Don't send WINDOW_UPDATE frames on closed streams.
  • Loading branch information
Lukasa committed Jul 12, 2016
2 parents a952ff0 + 0fcfecb commit 1cbc63c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
7 changes: 7 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Release History
===============

dev
---

*Bugfixes*

- Don't send WINDOWUPDATE frames on closed streams.

0.6.2 (2016-06-13)
------------------

Expand Down
4 changes: 3 additions & 1 deletion hyper/http20/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ def receive_data(self, event):
# Append the data to the buffer.
self.data.append(event.data)

if increment and not self.remote_closed:
stream_about_to_close = (event.stream_ended is not None)

if increment and not self.remote_closed and not stream_about_to_close:
with self._conn as conn:
conn.increment_flow_control_window(
increment, stream_id=self.stream_id
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def run_tests(self):
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: Implementation :: CPython',
],
install_requires=['h2>=2.3,<3.0', 'hyperframe>=3.2,<4.0'],
install_requires=['h2>=2.4,<3.0', 'hyperframe>=3.2,<4.0'],
tests_require=['pytest', 'requests', 'mock'],
cmdclass={'test': PyTest},
entry_points={
Expand Down
56 changes: 56 additions & 0 deletions test/test_hyper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
import h2.settings

from h2.frame_buffer import FrameBuffer
from hyperframe.frame import (
Frame, DataFrame, RstStreamFrame, SettingsFrame, PushPromiseFrame,
Expand Down Expand Up @@ -583,6 +585,60 @@ def test_closing_incomplete_stream(self, frame_buffer):
assert isinstance(f, RstStreamFrame)
assert 1 not in c.streams

def test_incrementing_window_after_close(self):
"""
Hyper does not attempt to increment the flow control window once the
stream is closed.
"""
# For this test, we want to send a response that has three frames at
# the default max frame size (16,384 bytes). That will, on the third
# frame, trigger the processing to increment the flow control window,
# which should then not happen.
f = SettingsFrame(0, settings={h2.settings.INITIAL_WINDOW_SIZE: 100})

c = HTTP20Connection('www.google.com')
c._sock = DummySocket()
c._sock.buffer = BytesIO(f.serialize())

# Open stream 1.
c.request('GET', '/')

# Check what data we've sent right now.
originally_sent_data = c._sock.queue[:]

# Swap out the buffer to get a GoAway frame.
length = 16384
total_length = (3 * 16384) + len(b'some more data')
e = Encoder()
h1 = HeadersFrame(1)
h1.data = e.encode(
[(':status', 200), ('content-length', '%d' % total_length)]
)
h1.flags |= set(['END_HEADERS'])

d1 = DataFrame(1)
d1.data = b'\x00' * length
d2 = d1
d3 = d1
d4 = DataFrame(1)
d4.data = b'some more data'
d4.flags |= set(['END_STREAM'])

buffer = BytesIO(
b''.join(f.serialize() for f in [h1, d1, d2, d3, d4])
)
c._sock.buffer = buffer

# Read the response
resp = c.get_response(stream_id=1)
assert resp.status == 200
assert resp.read() == b''.join(
[b'\x00' * (3 * length), b'some more data']
)

# We should have sent only one extra frame
assert len(originally_sent_data) + 1 == len(c._sock.queue)


class TestServerPush(object):
def setup_method(self, method):
Expand Down

0 comments on commit 1cbc63c

Please sign in to comment.