Browse Source

Log fatal messages once only

master
Neil Booth 8 years ago
parent
commit
f43c08d979
  1. 9
      lib/jsonrpc.py

9
lib/jsonrpc.py

@ -324,11 +324,14 @@ class JSONSessionBase(util.LoggedClass):
Flag the connection to close on a fatal error or too many errors.''' Flag the connection to close on a fatal error or too many errors.'''
version = self.version version = self.version
self.error_count += 1 self.error_count += 1
if not self.close_after_send:
fatal_log = None
if code in (version.PARSE_ERROR, version.INVALID_REQUEST): if code in (version.PARSE_ERROR, version.INVALID_REQUEST):
self.log_info(message) fatal_log = message
self.close_after_send = True
elif self.error_count >= 10: elif self.error_count >= 10:
self.log_info('too many errors, last: {}'.format(message)) fatal_log = 'too many errors, last: {}'.format(message)
if fatal_log:
self.log_info(fatal_log)
self.close_after_send = True self.close_after_send = True
return self.encode_payload(self.version.error_payload return self.encode_payload(self.version.error_payload
(message, code, id_)) (message, code, id_))

Loading…
Cancel
Save