Merge pull request #3 from YunoHost/new-exception

fix: handle OSError exception on asyncio sockets
This commit is contained in:
Bram 2021-01-21 19:46:32 +01:00 committed by GitHub
commit 7774e2baf2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -182,7 +182,7 @@ async def check_http_domain(ip, domain, nonce):
"status": "error_http_check_timeout", "status": "error_http_check_timeout",
"content": "Timed-out while trying to contact your server from outside. It appears to be unreachable. You should check that you're correctly forwarding port 80, that nginx is running, and that a firewall is not interfering.", "content": "Timed-out while trying to contact your server from outside. It appears to be unreachable. You should check that you're correctly forwarding port 80, that nginx is running, and that a firewall is not interfering.",
} }
except aiohttp.client_exceptions.ClientConnectorError as e: except (OSError, aiohttp.client_exceptions.ClientConnectorError) as e: # OSError: [Errno 113] No route to host
return { return {
"status": "error_http_check_connection_error", "status": "error_http_check_connection_error",
"content": "Connection error: could not connect to the requested domain, it's very likely unreachable. Raw error: " + str(e), "content": "Connection error: could not connect to the requested domain, it's very likely unreachable. Raw error: " + str(e),
@ -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"