Skip to content

Commit 4c678aa

Browse files
committed
fix: do not show unpack error exception which occures after PostgreSQL restart
1 parent 5f98fb4 commit 4c678aa

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

mamonsu/lib/plugin.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,12 @@ def _loop(self):
173173
return
174174
except Exception as e:
175175
trace = traceback.format_exc()
176-
self._log_exception(e, trace)
176+
# unpack_from error can happen if pg8000 was waiting for the response
177+
# from PostgreSQL on the socket but instead got nothing.
178+
# This error happens either due to an unstable network or if
179+
# PostgreSQL fails to send the results for the last queries while restarting
180+
if "unpack_from requires a buffer" not in trace:
181+
self._log_exception(e, trace)
177182
return
178183
# time interval btw sending metrics
179184
sleep_time = int(self.plugin_config('interval')) - int(time.time() - last_start)

mamonsu/plugins/pgsql/driver/connection.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
import os
33
import threading
44
import logging
5+
import struct
56

67
from mamonsu.plugins.pgsql.driver.pg8000 import connect
7-
from mamonsu.plugins.pgsql.driver.pg8000.core import ProgrammingError
8+
from mamonsu.plugins.pgsql.driver.pg8000.core import ProgrammingError, InterfaceError,InternalError,NotSupportedError,Error
9+
810

911

1012
class ConnectionInfo(object):
@@ -61,11 +63,7 @@ def query(self, query):
6163
self.connected = True
6264
except ProgrammingError as e:
6365
error_text = '{0}'.format(e)
64-
# unpack_from error can happen if pg8000 was waiting for the response
65-
# from PostgreSQL on the socket but instead got nothing.
66-
# This error happens either due to an unstable network or if
67-
# PostgreSQL fails to send the results for the last queries while restarting
68-
if error_text == 'no result set' or 'unpack_from' in error_text:
66+
if error_text == 'no result set':
6967
return None
7068
else:
7169
raise ProgrammingError(error_text)

0 commit comments

Comments
 (0)