Skip to content

Commit

Permalink
Fix handling asyncore and parsing error
Browse files Browse the repository at this point in the history
  • Loading branch information
vladtcvs committed Mar 15, 2018
1 parent fbe7b9c commit 3a27d27
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
21 changes: 15 additions & 6 deletions tempesta_fw/t/functional/helpers/deproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class ParseError(Exception):
class IncompliteMessage(ParseError):
pass


class HeaderCollection(object):
"""
A collection class for HTTP Headers. This class combines aspects of a list
Expand Down Expand Up @@ -547,11 +546,11 @@ def handle_read(self):
self.response_buffer = self.response_buffer[len(response.msg):]
except IncompliteMessage:
return
except ParseError as err:
except ParseError:
tf_cfg.dbg(4, ('Deproxy: Client: Can\'t parse message\n'
'<<<<<\n%s>>>>>'
% self.response_buffer))
raise err
raise
if len(self.response_buffer) > 0:
# TODO: take care about pipelined case
raise ParseError('Garbage after response end:\n```\n%s\n```\n' % \
Expand All @@ -573,7 +572,10 @@ def handle_write(self):

def handle_error(self):
_, v, _ = sys.exc_info()
error.bug('\tDeproxy: Client: %s' % v)
if type(v) == ParseError or type(v) == AssertionError:
raise v
else:
error.bug('\tDeproxy: Client: %s' % v)



Expand Down Expand Up @@ -685,14 +687,21 @@ def handle_accept(self):
self.connections.append(handler)
assert len(self.connections) <= self.conns_n, \
('Too lot connections, expect %d, got %d'
& (self.conns_n, len(self.connections)))
% (self.conns_n, len(self.connections)))

def handle_read_event(self):
asyncore.dispatcher.handle_read_event(self)

def active_conns_n(self):
return len(self.connections)

def handle_error(self):
_, v, _ = sys.exc_info()
raise Exception('\tDeproxy: Server %s:%d: %s' % (self.ip, self.port, v))
if type(v) == AssertionError:
raise v
else:
raise Exception('\tDeproxy: Server %s:%d: %s' % \
(self.ip, self.port, type(v)))

def handle_close(self):
self.stop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(self, *args, **kwargs):
base[0].server_response.headers.add('Content-Length', "%i" % base[1])
base[0].server_response.build_message()

base[0].response = chains.response_500()
base[0].response = chains.make_502_expected()

self.message_chains = [base[0]]
self.cookies = []
Expand Down
2 changes: 1 addition & 1 deletion tempesta_fw/t/functional/testers/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def generic_test_routine(self, tempesta_defconfig, message_chains):
try:
self.tester.run()
except ParseError as err:
self.assertTrue(False, msg=str(type(err)))
self.assertTrue(False, msg=err)

self.tempesta.get_stats()
self.assert_tempesta()
Expand Down

0 comments on commit 3a27d27

Please sign in to comment.