Skip to content

Commit

Permalink
Switching keep-alive to disconnect/reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
bboerst committed Jun 10, 2024
1 parent b8abe1e commit 8c13e11
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion collector/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,18 @@ def get_stratum_work(self, keep_alive=False):
self.publish_to_rabbitmq(document)

# Send a subscribe request every 2 minutes to keep the connection alive if keep_alive is enabled
if keep_alive and time.time() - last_subscribe_time > 120:
if keep_alive and time.time() - last_subscribe_time > 480:
LOG.info(f"Disconnecting from server for keep alive {self.purl.geturl()}")
self.close()
time.sleep(1)
self.init_socket() # Reinitialize the socket before reconnecting
self.sock.connect((self.purl.hostname, self.purl.port))
LOG.info(f"Reconnected to server {self.purl.geturl()}")
self.send_jsonrpc("mining.subscribe", [])
LOG.info("Resubscribed to pool notifications")
self.send_jsonrpc("mining.authorize", self.userpass.split(":"))
LOG.info("Reauthed with the pool")

LOG.info("Sending subscribe request to keep connection alive")
self.send_jsonrpc("mining.subscribe", [])
last_subscribe_time = time.time()
Expand Down

0 comments on commit 8c13e11

Please sign in to comment.