From f43c08d979d3ca99b9f2ab491751d050700d82c7 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Wed, 25 Jan 2017 20:46:22 +0900 Subject: [PATCH] Log fatal messages once only --- lib/jsonrpc.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/jsonrpc.py b/lib/jsonrpc.py index 977a0cc..a3b9cc8 100644 --- a/lib/jsonrpc.py +++ b/lib/jsonrpc.py @@ -324,12 +324,15 @@ class JSONSessionBase(util.LoggedClass): Flag the connection to close on a fatal error or too many errors.''' version = self.version self.error_count += 1 - if code in (version.PARSE_ERROR, version.INVALID_REQUEST): - self.log_info(message) - self.close_after_send = True - elif self.error_count >= 10: - self.log_info('too many errors, last: {}'.format(message)) - self.close_after_send = True + if not self.close_after_send: + fatal_log = None + if code in (version.PARSE_ERROR, version.INVALID_REQUEST): + fatal_log = message + elif self.error_count >= 10: + fatal_log = 'too many errors, last: {}'.format(message) + if fatal_log: + self.log_info(fatal_log) + self.close_after_send = True return self.encode_payload(self.version.error_payload (message, code, id_))