Verified Commit a13b2a38 authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Catch Native TimeoutError exception on HTTP client request.

parent 75dc6244
Pipeline #36574 failed with stages
in 31 seconds
# ----------------------------------------------------------------------
# HTTP Client
# ----------------------------------------------------------------------
# Copyright (C) 2007-2020 The NOC Project
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
......@@ -190,7 +190,7 @@ async def fetch(
except OSError as e:
metrics["httpclient_timeouts"] += 1
return ERR_TIMEOUT, {}, b"Connection error: %s" % smart_bytes(e)
except asyncio.TimeoutError:
except (asyncio.TimeoutError, TimeoutError):
metrics["httpclient_timeouts"] += 1
return ERR_TIMEOUT, {}, b"Connection timed out"
# Proxy CONNECT
......@@ -205,7 +205,7 @@ async def fetch(
writer.write(smart_bytes(req))
try:
await asyncio.wait_for(writer.drain(), request_timeout)
except asyncio.TimeoutError:
except (asyncio.TimeoutError, TimeoutError):
metrics["httpclient_proxy_timeouts"] += 1
return ERR_TIMEOUT, {}, b"Timed out while sending request to proxy"
# Wait for proxy response
......@@ -213,7 +213,7 @@ async def fetch(
while not parser.is_headers_complete():
try:
data = await asyncio.wait_for(reader.read(max_buffer_size), request_timeout)
except asyncio.TimeoutError:
except (asyncio.TimeoutError, TimeoutError):
metrics["httpclient_proxy_timeouts"] += 1
return ERR_TIMEOUT, {}, b"Timed out while sending request to proxy"
received = len(data)
......@@ -282,7 +282,7 @@ async def fetch(
except ConnectionResetError:
metrics["httpclient_timeouts"] += 1
return ERR_TIMEOUT, {}, b"Connection reset while sending request"
except asyncio.TimeoutError:
except (asyncio.TimeoutError, TimeoutError):
metrics["httpclient_timeouts"] += 1
return ERR_TIMEOUT, {}, b"Timed out while sending request"
parser = HttpParser()
......@@ -293,7 +293,7 @@ async def fetch(
is_eof = not data
except (asyncio.IncompleteReadError, ConnectionResetError):
is_eof = True
except asyncio.TimeoutError:
except (asyncio.TimeoutError, TimeoutError):
metrics["httpclient_timeouts"] += 1
return ERR_READ_TIMEOUT, {}, b"Request timed out"
if is_eof:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment