Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: Add CONNECT_TIMEOUT option #112

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
qinxuye marked this conversation as resolved.
Show resolved Hide resolved
Loading