Skip to content

Commit 1c8b855

Browse files
authored
fix: ensure client keepalive < server keepalive to avoid client keepalive desync errors (#1555)
uvicorn closes idle keep-alive connections after 5s by default ([ref](https://uvicorn.dev/settings/#timeouts)) while the aiohttp client keeps them pooled for 15s by default ([ref](https://docs.aiohttp.org/en/stable/client_reference.html#connectors)), causing ServerDisconnectedError when the client reuses a socket the server already closed. This PR set the client TCPConnector `keepalive_timeout` to 15s and the uvicorn `timeout_keep_alive` to 30s so pooled sockets are guaranteed live when reused. Signed-off-by: Ananth Subramaniam <ansubramania@nvidia.com>
1 parent cf8fbed commit 1c8b855

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

nemo_gym/server_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def set_global_aiohttp_client(cfg: GlobalAIOHTTPAsyncClientConfig) -> ClientSess
110110
connector=TCPConnector(
111111
limit=cfg.global_aiohttp_connector_limit // num_workers,
112112
limit_per_host=cfg.global_aiohttp_connector_limit_per_host // num_workers,
113+
keepalive_timeout=15.0,
113114
),
114115
timeout=ClientTimeout(),
115116
cookie_jar=DummyCookieJar(),
@@ -672,6 +673,8 @@ def filter(self, record: LogRecord) -> bool:
672673
timeout_graceful_shutdown=0.5,
673674
# Some workers may take a while for imports and setup_webserver.
674675
timeout_worker_healthcheck=30,
676+
# Ensure server keepalive > client keepalive
677+
timeout_keep_alive=30,
675678
)
676679

677680
if server.config.num_workers and server.config.num_workers > 1:

0 commit comments

Comments
 (0)