Skip to content

Commit e161f06

Browse files
joaomariolagopatrickelectric
authored andcommitted
core:services:kraken: Fix 5 min timeout
* Make sure kraken does not keeps reattaching to stream logs due to internal aiohttp 5 minutes timeout
1 parent 9abca66 commit e161f06

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

core/services/kraken/harbor/container.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ async def get_running_container_by_name(cls, container_name: str) -> ContainerMo
113113

114114
@classmethod
115115
async def get_container_log_by_name(cls, container_name: str) -> AsyncGenerator[str, None]:
116-
async with DockerCtx() as client:
116+
async with DockerCtx(timeout=0) as client:
117117
try:
118118
container = await cls.get_raw_container_by_name(client, container_name)
119119
except ContainerNotFound as error:

core/services/kraken/harbor/contexts.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from typing import Any
1+
from typing import Any, Optional
22

3+
import aiohttp
34
from aiodocker import Docker
45

56

@@ -8,8 +9,20 @@ class DockerCtx:
89
Context manager for Docker clients.
910
"""
1011

11-
def __init__(self) -> None:
12-
self._client: Docker = Docker()
12+
def __init__(self, timeout: Optional[int] = None) -> None:
13+
if timeout is None:
14+
self._client: Docker = Docker()
15+
else:
16+
# aiodocker will not create a session if is different from None
17+
self._client: Docker = Docker(session=True) # type: ignore
18+
# We insert a new session with desired timeout
19+
self._client.session = self._client.session = aiohttp.ClientSession(
20+
connector=self._client.connector,
21+
timeout=aiohttp.ClientTimeout(
22+
total=None if timeout == 0 else timeout,
23+
sock_read=None if timeout == 0 else timeout,
24+
),
25+
)
1326

1427
async def __aenter__(self) -> Docker:
1528
return self._client

0 commit comments

Comments
 (0)