close socket when testing connections

rather than relying on garbage collection
This commit is contained in:
Min RK
2017-06-08 15:27:49 +02:00
parent 38e772dfec
commit a5fbc0351f

View File

@@ -40,7 +40,7 @@ def can_connect(ip, port):
if ip in {'', '0.0.0.0'}:
ip = '127.0.0.1'
try:
socket.create_connection((ip, port))
socket.create_connection((ip, port)).close()
except socket.error as e:
if e.errno not in {errno.ECONNREFUSED, errno.ETIMEDOUT}:
app_log.error("Unexpected error connecting to %s:%i %s", ip, port, e)