Github Mirror / telegraf-plugins: fe3d6e83




Implement a retry on initial read from socket (utilities/telegraf-plugins#6)

Implement a retry on initial read from socket (utilities/telegraf-plugins#6)

This should cater to cases where the tor-daemon is (exceptionally) slow to start responding.

Commit fe3d6e83.

Authored 2022-06-15T17:49:58.000+01:00 by B Tasker in project Github Mirror / telegraf-plugins

+3 lines -1 lines

Commit Signature

Changes

diff --git a/tor-daemon/tor-daemon.py b/tor-daemon/tor-daemon.py
--- a/tor-daemon/tor-daemon.py
+++ b/tor-daemon/tor-daemon.py
# @@ -45,6 +45,7 @@ def send_and_respond(sock, command):
#
# # Read the response
# res = []
# + read_attempts = 0
# while True:
# try:
# data = sock.recv(1024)
# @@ -53,9 +54,10 @@ def send_and_respond(sock, command):
# res.append(data.decode())
# except socket.timeout as e:
# if e.args[0] == "timed out":
# - if len(res) == 0:
# + if len(res) == 0 and read_attempts < 2 and len(res) == 0:
# # Wait a little longer
# time.sleep(0.5)
# + read_attempts += 1
# continue
# else:
# # Looks like we got our read
#