diff --git a/etc/modules/livestatus.cfg b/etc/modules/livestatus.cfg index 523f31c..eaad3d5 100644 --- a/etc/modules/livestatus.cfg +++ b/etc/modules/livestatus.cfg @@ -18,4 +18,6 @@ define module { modules logstore-sqlite #debug /tmp/ls.debug ; Enable only for debugging this module #debug_queries 0 ; Set to 1 to dump queries/replies too (very verbose) + #socket_read_timeout 90 + #socket_write_timeout 90 } diff --git a/module/livestatus_client_thread.py b/module/livestatus_client_thread.py index 3f659bf..0c1388e 100644 --- a/module/livestatus_client_thread.py +++ b/module/livestatus_client_thread.py @@ -51,7 +51,8 @@ class Interrupted(LiveStatusClientError): class LiveStatusClientThread(threading.Thread): ''' A LiveStatus Client Thread will handle a full LS client connection. ''' - def __init__(self, client_sock, client_address, livestatus_broker): + def __init__(self, client_sock, client_address, livestatus_broker, + socket_read_timeout=90, socket_write_timeout=90): ''' :param client_sock: The socket instance of the client. :param client_address: The address of the client. @@ -72,7 +73,8 @@ def __init__(self, client_sock, client_address, livestatus_broker): now = time.time() self.start_time = now self.last_read = self.last_write = now - self.write_timeout = self.read_timeout = 90 # TODO: use parameters from somewhere.. + self.write_timeout = socket_write_timeout + self.read_timeout = socket_read_timeout self.logger = logger self.last_query_time = None self.requests_received = 0 # number of requests received diff --git a/module/module.py b/module/module.py index 625d25f..e3de1f3 100644 --- a/module/module.py +++ b/module/module.py @@ -110,6 +110,8 @@ def __init__(self, modconf): self.host = '0.0.0.0' self.port = getattr(modconf, 'port', None) self.socket = getattr(modconf, 'socket', None) + self.socket_read_timeout = int(getattr(modconf, 'socket_read_timeout', 90)) + self.socket_write_timeout = int(getattr(modconf, 'socket_read_timeout', 90)) if self.port == 'none': self.port = None if self.port: @@ -368,7 +370,9 @@ def _listening_thread_run(self): full_safe_close(sock) continue - new_client = self.client_connections[sock] = LiveStatusClientThread(sock, address, self) + new_client = self.client_connections[sock] = LiveStatusClientThread( + sock, address, self, + self.socket_read_timeout, self.socket_write_timeout) new_client.start() self.livestatus.count_event('connections') # end for s in inputready: