Skip to content

Commit

Permalink
string-match specific error caused by eventlet bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbennett committed Oct 27, 2016
1 parent 0758d21 commit e769df2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
9 changes: 6 additions & 3 deletions nameko/web/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,14 @@ def run(self):
def process_request(self, sock, address):
try:
self._serv.process_request((sock, address))
except OSError:
except OSError as exc:
# OSError("raw readinto() returned invalid length")
# can be raised when a client disconnects very early.
# can be raised when a client disconnects very early as a result
# of an eventlet bug: https://github.com/eventlet/eventlet/pull/353
# See https://github.com/onefinestay/nameko/issues/368
pass
if "raw readinto() returned invalid length" in str(exc):
return
raise

def start(self):
if not self._starting:
Expand Down
31 changes: 14 additions & 17 deletions test/web/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,49 +40,46 @@ def test_broken_pipe(
assert web_session.get('/').text == ''


def test_client_disconnect_os_error(
def test_other_socket_error(
container_factory, web_config, web_config_port, web_session
):
""" Regression for https://github.com/onefinestay/nameko/issues/368
"""
container = container_factory(ExampleService, web_config)
container.start()

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', web_config_port))

with patch.object(HttpOnlyProtocol, 'handle_one_request') as handle:
handle.side_effect = OSError('raw readinto() returned invalid length')
with patch.object(BaseHTTPServer.BaseHTTPRequestHandler, 'finish') as fin:
fin.side_effect = socket.error('boom')
s.sendall(b'GET / \r\n\r\n')
s.recv(10)
s.close()

# server should still work
assert web_session.get('/').text == ''
# takes down container
with pytest.raises(socket.error) as exc:
container.wait()
assert 'boom' in str(exc)


def test_other_error(
def test_client_disconnect_os_error(
container_factory, web_config, web_config_port, web_session
):
""" Regression for https://github.com/onefinestay/nameko/issues/368
"""
container = container_factory(ExampleService, web_config)
container.start()

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', web_config_port))

class OtherError(Exception):
pass

with patch.object(BaseHTTPServer.BaseHTTPRequestHandler, 'finish') as fin:
fin.side_effect = OtherError('boom')
with patch.object(HttpOnlyProtocol, 'handle_one_request') as handle:
handle.side_effect = OSError('raw readinto() returned invalid length')
s.sendall(b'GET / \r\n\r\n')
s.recv(10)
s.close()

# takes down container
with pytest.raises(OtherError) as exc:
container.wait()
assert 'boom' in str(exc)
# server should still work
assert web_session.get('/').text == ''


@pytest.mark.parametrize(['source', 'result'], [
Expand Down

0 comments on commit e769df2

Please sign in to comment.