Skip to content

Commit bdfc70d

Browse files
authored
Add timeout configuration for aiohttp ClientSession using CONTROL_PLANE_TIMEOUT (permitio#286)
1 parent a60c07d commit bdfc70d

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

horizon/opal_relay_api.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from urllib.parse import urljoin
66
from uuid import UUID
77

8+
import aiohttp
89
from aiohttp import ClientSession
910
from fastapi import status
1011
from fastapi.encoders import jsonable_encoder
@@ -134,7 +135,9 @@ async def relay_session(self) -> ClientSession:
134135
) from e
135136
self._relay_token = obj.token
136137
self._relay_session = ClientSession(
137-
headers={"Authorization": f"Bearer {self._relay_token}"}, trust_env=True
138+
headers={"Authorization": f"Bearer {self._relay_token}"},
139+
trust_env=True,
140+
timeout=aiohttp.ClientTimeout(total=sidecar_config.CONTROL_PLANE_TIMEOUT),
138141
)
139142
return self._relay_session
140143

horizon/proxy/api.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ async def proxy_request_to_cloud_service(
172172
path: str,
173173
cloud_service_url: str,
174174
additional_headers: dict[str, str],
175+
timeout: int = sidecar_config.CONTROL_PLANE_TIMEOUT,
175176
) -> Response:
176177
auth_header = request.headers.get("Authorization")
177178
if auth_header is None:
@@ -200,9 +201,7 @@ async def proxy_request_to_cloud_service(
200201

201202
logger.info(f"Proxying request: {request.method} {path}")
202203

203-
async with aiohttp.ClientSession(
204-
trust_env=True,
205-
) as session:
204+
async with aiohttp.ClientSession(trust_env=True, timeout=aiohttp.ClientTimeout(total=timeout)) as session:
206205
if request.method == HTTP_GET:
207206
async with session.get(path, headers=headers, params=params) as backend_response:
208207
return await proxy_response(backend_response)

0 commit comments

Comments
 (0)