Commit 2c9c1f94 authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Merge branch 'patch-avs-add-timeout-exception' into 'master'

Catch Native TimeoutError exception on HTTP client request.

See merge request !6380

(cherry picked from commit 273cee03)

a13b2a38 Catch Native TimeoutError exception on HTTP client request.
b78f6e2d Fix typo.
parent bd263dfb
Pipeline #36577 passed with stages
in 25 minutes and 56 seconds
# ----------------------------------------------------------------------
# HTTP Client
# ----------------------------------------------------------------------
# Copyright (C) 2007-2020 The NOC Project
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
......@@ -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