Skip to content
Snippets Groups Projects
Verified Commit c974f4fd authored by David Hoese's avatar David Hoese
Browse files

Set socket timeout on loggernet receiver

parent cb58f89a
No related branches found
No related tags found
No related merge requests found
......@@ -19,14 +19,24 @@ LOG = logging.getLogger(__name__)
def _ldmp_worker(host, port, queue, run_event):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
s.settimeout(30.0)
data_str = ""
while run_event.is_set():
# Get the data from the LDMP server
while not data_str or data_str[-1] != '\n':
data = s.recv(2048)
try:
data = s.recv(2048)
except TimeoutError:
LOG.info("Timeout error (30 seconds) from LDMP socket")
if not run_event.is_set():
LOG.debug("Signal to stop background process seen during receive timeout")
break
data_str += data.decode('utf8')
if not run_event.is_set():
continue
# Acknowledge that we received the record
s.send(b'\r')
......@@ -63,9 +73,10 @@ class LDMPReceiver(object):
if not self._started:
return
self._run_event.clear()
LOG.info("Background process told to stop")
self._worker.join()
self._started = False
LOG.info("Background thread successfully terminated")
LOG.info("Background process successfully terminated")
def close(self):
return self.stop()
......@@ -80,7 +91,7 @@ class LDMPReceiver(object):
def __iter__(self):
try:
while True:
yield self._queue.get(timeout=600) # 5 minutes
yield self._queue.get(timeout=300) # 5 minutes
except KeyboardInterrupt:
LOG.info("Keyboard interrupt encountered, killing background "
"thread...")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment