Skip to content

[Core] Debugging flaky redis connection on windows - #67085

Merged
rueian merged 6 commits into
ray-project:masterfrom
Kunchd:windows-redis-keepalive
Oct 19, 2026
Merged

rueian merged 6 commits into
ray-project:masterfrom
Kunchd:windows-redis-keepalive

Conversation

@Kunchd

@Kunchd Kunchd commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

We have recently observed after #65424 (introduced keep alive tcp connection between gcs and redis on all operating systems) was merged, redis_async_context_test would fail periodically on Windows in postmerge. Initial investigation on the failed runs showed each of the failed test logging something similar to the following before failure:

[2026-10-13T20:48:54Z] [2026-10-13 20:48:49,026 I 4644 8916] (redis_async_context_test.exe) redis_context.cc:725: Attempting to connect to address 127.0.0.1:3768.
[2026-10-13T20:48:54Z] [2026-10-13 20:48:49,026 E 4644 8916] (redis_async_context_test.exe) redis_context.cc:735: Giving up connecting to Redis due to a non-retryable error: IOError: Failed to enable TCP keepalive on the Redis connection to 127.0.0.1:3768: Input/output error. Set RAY_redis_tcp_keepalive_interval_seconds=0 to disable TCP keepalive if this platform cannot support it.
[2026-10-13T20:48:54Z] [2026-10-13 20:48:49,026 E 4644 8916] (redis_async_context_test.exe) redis_context.cc:735: Giving up connecting to Redis due to a non-retryable error: IOError: Failed to enable TCP keepalive on the Redis connection to 127.0.0.1:3768: Input/output error. Set RAY_redis_tcp_keepalive_interval_seconds=0 to disable TCP keepalive if this platform cannot support it.
[2026-10-13T20:48:54Z] src/ray/gcs/store_client/tests/redis_async_context_test.cc(325): error: Value of: context.Connect("127.0.0.1", TEST_REDIS_SERVER_PORTS.front(), "", "").ok()

We have managed to replicate the issue on our CI machine, and upon adding more detailed logging, we have observed the following.

On Windows, when we attempt to configure keepalive via hiredis's redisEnableKeepAliveWithInterval immediately after making the async connection, we periodically run into the IO error shown above. However, when we broke down the individudal components of redisEnableKeepAliveWithInterval, we observed that the system actually failed due to WSA error=10022 when we attempted to set SO_KEEPALIVE on the async connection.

What this PR introduces

Thus, this PR introduces a select to wait on the async connection in windows. With this change, we will only write keepalive to the connection once we are sure it is ready (per select's documentation ). The change has been stress tested on the redis_async_context_test and we have observed the original flaky failures go away.

Related issues

Additional information

Passing redis test run in post merge: https://buildkite.com/ray-project/postmerge/builds/20371#01a14b8e-d72f-4de4-8426-35d38340f0bc

@Kunchd
Kunchd force-pushed the windows-redis-keepalive branch from b5cb554 to bf1ae96 Compare October 16, 2026 19:47
@Kunchd
Kunchd marked this pull request as ready for review October 16, 2026 22:54
@Kunchd
Kunchd requested a review from a team as a code owner October 16, 2026 22:54

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a Windows-specific fix for configuring TCP keepalive on asynchronous Redis connections. Since Winsock does not support setting socket options while a connection is in progress, a new helper function WaitForRedisConnect is added to wait for the connection to complete using select before applying the keepalive configuration. Additionally, a timeout constant kRedisConnectWaitTimeoutSeconds is defined. There are no review comments to address, and I have no further feedback to provide.

@Kunchd Kunchd added the go add ONLY when ready to merge, run all tests label Oct 16, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 75055d4. Configure here.

@rueian

rueian commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

LGTM. One thing to add: Setting keepalive before connect() would be cleaner (SO_KEEPALIVE docs allow it), but hiredis creates the socket and connects it in one step (net.c), with no hook in between. So we wait for the connection to be ready here.

@rueian
rueian enabled auto-merge (squash) October 16, 2026 23:21
@ray-gardener ray-gardener Bot added the core Issues that should be addressed in Ray Core label Oct 17, 2026
@github-actions
github-actions Bot disabled auto-merge October 17, 2026 19:51
@rueian
rueian merged commit 6a3ba37 into ray-project:master Oct 19, 2026
7 checks passed
@Kunchd
Kunchd deleted the windows-redis-keepalive branch October 19, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants