Skip to content

Commit d04cd03

Browse files
committed
improved handling connection timeout from agent to server
1 parent a327c51 commit d04cd03

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

agent/kraken/agent/server.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import os
1616
import json
1717
import time
18+
import socket
1819
import logging
1920
import datetime
2021
import urllib.request
@@ -51,7 +52,7 @@ def _send_http_request(url, data):
5152

5253
while resp is None:
5354
try:
54-
with urllib.request.urlopen(req) as f:
55+
with urllib.request.urlopen(req, timeout=120) as f:
5556
resp = f.read().decode('utf-8')
5657
# except socket.error as e:
5758
# if e.errno in connection_errors:
@@ -66,6 +67,9 @@ def _send_http_request(url, data):
6667
except ConnectionError as e:
6768
log.warning('connection problem to %s: %s, trying one more time in 5s', url, str(e))
6869
time.sleep(5)
70+
except socket.timeout:
71+
log.warning('connection timeout to %s, trying one more time in 5s', url)
72+
time.sleep(5)
6973
except Exception:
7074
log.exception('some problem with connecting to server to %s', url)
7175
log.info('trying one more time in 5s')

0 commit comments

Comments
 (0)