fix: handle OSError exception on asyncio sockets

This commit is contained in:
Laurent Peuch 2021-01-13 01:58:02 +01:00
parent d3abbf0f1e
commit 9ef4dd6d35

View file

@ -295,7 +295,7 @@ async def check_port_is_open(ip, port):
try: try:
_, writer = await asyncio.wait_for(futur, timeout=2) _, writer = await asyncio.wait_for(futur, timeout=2)
except (asyncio.TimeoutError, ConnectionRefusedError): except (asyncio.TimeoutError, ConnectionRefusedError, OSError): # OSError: [Errno 113] No route to host
return False return False
except Exception: except Exception:
import traceback import traceback
@ -350,7 +350,7 @@ async def check_smtp(request):
try: try:
reader, writer = await asyncio.wait_for(futur, timeout=2) reader, writer = await asyncio.wait_for(futur, timeout=2)
except (asyncio.TimeoutError, ConnectionRefusedError): except (asyncio.TimeoutError, ConnectionRefusedError, OSError): # OSError: [Errno 113] No route to host
return json_response({ return json_response({
'status': "error_smtp_unreachable", 'status': "error_smtp_unreachable",
'content': "Could not open a connection on port 25, probably because of a firewall or port forwarding issue" 'content': "Could not open a connection on port 25, probably because of a firewall or port forwarding issue"