Skip to content

Commit

Permalink
FEAT: Add CONNECT_TIMEOUT option (#112)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: qinxuye <[email protected]>
  • Loading branch information
3 people authored Nov 25, 2024
1 parent d6ec36b commit 7b9f181
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
10 changes: 8 additions & 2 deletions python/xoscar/backends/communication/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from urllib.parse import urlparse

from ..._utils import to_binary
from ...constants import XOSCAR_UNIX_SOCKET_DIR
from ...constants import XOSCAR_CONNECT_TIMEOUT, XOSCAR_UNIX_SOCKET_DIR
from ...serialization import AioDeserializer, AioSerializer, deserialize
from ...utils import classproperty, implements, is_py_312, is_v6_ip
from .base import Channel, ChannelType, Client, Server
Expand Down Expand Up @@ -291,7 +291,13 @@ async def connect(
) -> "Client":
host, port_str = dest_address.rsplit(":", 1)
port = int(port_str)
(reader, writer) = await asyncio.open_connection(host=host, port=port, **kwargs)
config = kwargs.get("config", {})
connect_timeout = config.get("connect_timeout", XOSCAR_CONNECT_TIMEOUT)
fut = asyncio.open_connection(host=host, port=port)
try:
reader, writer = await asyncio.wait_for(fut, timeout=connect_timeout)
except asyncio.TimeoutError:
raise ConnectionError("connect timeout")
channel = SocketChannel(
reader, writer, local_address=local_address, dest_address=dest_address
)
Expand Down
2 changes: 1 addition & 1 deletion python/xoscar/backends/indigen/tests/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ async def test_server_closed():

# check if error raised normally when subprocess killed
task = asyncio.create_task(actor_ref.sleep(10))
await asyncio.sleep(0)
await asyncio.sleep(0.1)

# kill subprocess 1
process = list(pool._sub_processes.values())[0]
Expand Down
2 changes: 2 additions & 0 deletions python/xoscar/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@

# unix socket.
XOSCAR_UNIX_SOCKET_DIR = XOSCAR_TEMP_DIR / "socket"

XOSCAR_CONNECT_TIMEOUT = 8

0 comments on commit 7b9f181

Please sign in to comment.