Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure socket read and write timeouts for LiveStatusClientThread instances #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions etc/modules/livestatus.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 4 additions & 2 deletions module/livestatus_client_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion module/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down