-
Notifications
You must be signed in to change notification settings - Fork 867
feat: TCP keepalive, reverse-channel probe, list_models cache, .pth atomic write, launch exemption #4845
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
Merged
qinxuye
merged 3 commits into
xorbitsai:main
from
m199369309:fix/keepalive-reverse-ping-pth-atomic-launch-exempt
Apr 26, 2026
+182
−28
Merged
feat: TCP keepalive, reverse-channel probe, list_models cache, .pth atomic write, launch exemption #4845
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| """ | ||
| Monkey-patch xoscar SocketClient.connect to enable TCP keepalive on every | ||
| RPC connection. | ||
|
|
||
| Without this, idle TCP connections between Supervisor and Worker are silently | ||
| dropped by stateful network devices (firewalls, NAT gateways) whose TCP | ||
| session timeout (commonly 15-45 min) is shorter than the application idle | ||
| window. xoscar's ``Router._cache`` only checks ``writer.is_closing()`` | ||
| which stays ``False`` after a silent drop, so the dead connection is reused | ||
| and the next RPC hangs until OS-level TCP retransmission timeout (60-120 s). | ||
|
|
||
| Enabling ``SO_KEEPALIVE`` with ``TCP_KEEPIDLE=60 / TCP_KEEPINTVL=10 / | ||
| TCP_KEEPCNT=3`` causes the kernel to probe idle connections every 60 s and | ||
| declare them dead within 90 s -- well below typical firewall timeouts. | ||
| """ | ||
|
|
||
| import logging | ||
| import socket | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| _patched = False | ||
|
|
||
|
|
||
| def patch_xoscar_socket_keepalive(): | ||
| """Apply the keepalive patch exactly once (idempotent).""" | ||
| global _patched | ||
| if _patched: | ||
| return | ||
| _patched = True | ||
|
|
||
| try: | ||
| from xoscar.backends.communication.socket import SocketClient | ||
| except ImportError: | ||
| logger.debug("xoscar not installed, skipping keepalive patch") | ||
| return | ||
|
|
||
| _original_connect = SocketClient.connect | ||
|
|
||
| @staticmethod | ||
| async def _patched_connect(dest_address, local_address=None, **kwargs): | ||
| client = await _original_connect( | ||
| dest_address, local_address=local_address, **kwargs | ||
| ) | ||
| try: | ||
| sock = client.channel.writer.get_extra_info("socket") | ||
| if sock is not None: | ||
| sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) | ||
| if hasattr(socket, "TCP_KEEPIDLE"): | ||
| # Linux | ||
| sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 60) | ||
| sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 10) | ||
| sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 3) | ||
| elif hasattr(socket, "TCP_KEEPALIVE"): | ||
| # macOS: TCP_KEEPALIVE is the equivalent of TCP_KEEPIDLE | ||
| sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPALIVE, 60) | ||
| except Exception: | ||
| logger.debug( | ||
| "Failed to set TCP keepalive on xoscar connection to %s", | ||
| dest_address, | ||
| exc_info=True, | ||
| ) | ||
| return client | ||
|
|
||
| SocketClient.connect = _patched_connect | ||
| logger.info("xoscar SocketClient.connect patched with TCP keepalive") | ||
|
|
||
|
|
||
| # Auto-apply on import | ||
| patch_xoscar_socket_keepalive() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.