Skip to content

[Refactor][GCS] Merge RedisAsioClient into RedisAsyncContext - #49000

Merged
jjyao merged 5 commits into
ray-project:masterfrom
MortalHappiness:feature/merge-redisasioclient-asynccontext
Dec 5, 2024
Merged

jjyao merged 5 commits into
ray-project:masterfrom
MortalHappiness:feature/merge-redisasioclient-asynccontext

Conversation

@MortalHappiness

@MortalHappiness MortalHappiness commented Nov 30, 2024 •

Copy link
Copy Markdown
Member

Why are these changes needed?

While working on #48781, we found that RedisAsioClient and RedisAsyncContext strongly depends on each other, and it is a 1-1 mapping. Therefore, we decide to merge the implementation of RedisAsioClient into RedisAsyncContext to make it self-contained.

The class diagram before this PR:

image

Note: redisAsyncContext implicitly uses RedisAsioClient via the callback function.

The class diagram after this PR:

image

Related issue number

N/A

Checks

@MortalHappiness MortalHappiness added the go add ONLY when ready to merge, run all tests label Nov 30, 2024
@MortalHappiness
MortalHappiness marked this pull request as ready for review November 30, 2024 12:09
@MortalHappiness
MortalHappiness requested a review from a team as a code owner November 30, 2024 12:09
Comment thread src/ray/gcs/redis_async_context.h Resolved
Comment thread src/ray/gcs/redis_async_context.h Resolved
Comment thread src/ray/gcs/redis_async_context.h Outdated

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.

Any chance for documentation? operate, cleanup, and most of the function names are confusing without inspecting the code, please add some documentations, thanks.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Acutally I just copy them from the original asio.h. There is also no comment there. But I'll try to add some comments.

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.

Thank you!

Comment thread src/ray/gcs/redis_async_context.cc Outdated

@dentiny dentiny Nov 30, 2024 •

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.

I'm curious about the logic:

  • From doc, the bytes read is passed to callback
  • How do we know all bytes have been read from socket?
  • LL145 shows we directly mark ongoing read/write operation as false

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good question. This might be due to a historical reason. We can ask other team members why we don't use async_read here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

cc @jjyao

Comment thread src/ray/gcs/redis_async_context.h Outdated

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.

Actually I'm not quite sure we should use mutex and multi-threading here.
The only operation which might involve multi-threaded operation is operate invoked from another thread, all other operations are posted into io_service; curious why do we need concurrent operate calls?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Actually, I don't know either. But I suspect that the predecessors decided to use a mutex because they saw this: https://github.com/redis/hiredis/blob/8d8703ee6149ffd3b38cebedd71ad8d1fac63cc7/README.md?plain=1#L152.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

They want to make redisAsyncContext thread-safe.

@MortalHappiness
MortalHappiness force-pushed the feature/merge-redisasioclient-asynccontext branch from bef27a1 to 334dfe6 Compare November 30, 2024 13:26

@jjyao jjyao 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.

LG. There is merge conflict.

Comment thread src/ray/gcs/redis_async_context.cc Outdated

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.

This used to be empty, is it intentional change?

@MortalHappiness MortalHappiness Dec 4, 2024 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@MortalHappiness
MortalHappiness force-pushed the feature/merge-redisasioclient-asynccontext branch from 334dfe6 to 3be9873 Compare December 4, 2024 23:04
@jjyao
jjyao merged commit 54050c9 into ray-project:master Dec 5, 2024
namespace ray {
namespace gcs {
// Adaptor callback functions for hiredis redis_async_context->ev
void CallbackAddRead(void *);

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.

You don't need to place it in header file...

ujjawal-khare pushed a commit to ujjawal-khare-27/ray that referenced this pull request Dec 17, 2024
edoakes pushed a commit that referenced this pull request Jun 24, 2026
…64204)

## Description

While testing, `gcs_server` crashed with a SIGSEGV during a Redis
connection error (failover). Looking for a fix I found #48781, which
solves it by reconnecting to Redis, but it was closed as stale without
being merged. Its main blocker at the time (a dependency cycle in the
GCS Redis client) has since been resolved by #49000 and #55655, so this
PR ports that reconnect approach onto the current version.

When the Redis connection is lost, an in-flight request retries against
the released connection and dereferences a null pointer, crashing the
GCS. This PR reconnects to Redis when the connection is dead so requests
retry on a healthy connection instead of crashing.


## Related issues

- Fixes #53475
- Based on #48781 by @MortalHappiness (closed without merge); credit for
the original design.

## Additional information

Reproduction:
1. Run a cluster with GCS fault tolerance backed by an HA Redis.
2. While the cluster is up, trigger a Redis primary failover e.g.
kill/replace the Redis primary so a replica is promoted.
3. Before this PR, `gcs_server` exits with signal 11 and the head pod
restarts; after this PR it reconnects to the new primary and continues.

The exact crash we observed:

```
2026-06-18 04:54:00,110 ERROR scripts.py:1219 -- Some Ray subprocesses exited unexpectedly:
  gcs_server [exit code=-11 (signal 11)]

[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474: *** SIGSEGV received at time=1781726136 on cpu 0 ***
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474: PC: @     0x55719802efb8  (unknown)  ray::gcs::RedisRequestContext::RedisResponseFn()
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474:     @     0x7f6c34fb6520  (unknown)  (unknown)
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474:     @     0x55719802f1f9       1168  ray::gcs::RedisRequestContext::Run()
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474:     @     0x55719801a748        224  ray::gcs::RedisStoreClient::AsyncCheckHealth()
```

---

## Update:
I first took the reconnect approach above, but a robust in-place
reconnect needs `Connect()` to be non-fatal (it `RAY_CHECK`s today, so a
transient failover still aborts `gcs_server`) - the larger refactor that
stalled #48781. So this PR instead takes the minimal fix: null-guard the
dereference so the request fails gracefully instead of crashing, and GCS
fault tolerance recovers as today. Full reconnect is left as a follow-up
(#48781).

Signed-off-by: Dongjun Na <[email protected]>
limarkdcunha pushed a commit to limarkdcunha/ray that referenced this pull request Jun 30, 2026
…ay-project#64204)

## Description

While testing, `gcs_server` crashed with a SIGSEGV during a Redis
connection error (failover). Looking for a fix I found ray-project#48781, which
solves it by reconnecting to Redis, but it was closed as stale without
being merged. Its main blocker at the time (a dependency cycle in the
GCS Redis client) has since been resolved by ray-project#49000 and ray-project#55655, so this
PR ports that reconnect approach onto the current version.

When the Redis connection is lost, an in-flight request retries against
the released connection and dereferences a null pointer, crashing the
GCS. This PR reconnects to Redis when the connection is dead so requests
retry on a healthy connection instead of crashing.


## Related issues

- Fixes ray-project#53475
- Based on ray-project#48781 by @MortalHappiness (closed without merge); credit for
the original design.

## Additional information

Reproduction:
1. Run a cluster with GCS fault tolerance backed by an HA Redis.
2. While the cluster is up, trigger a Redis primary failover e.g.
kill/replace the Redis primary so a replica is promoted.
3. Before this PR, `gcs_server` exits with signal 11 and the head pod
restarts; after this PR it reconnects to the new primary and continues.

The exact crash we observed:

```
2026-06-18 04:54:00,110 ERROR scripts.py:1219 -- Some Ray subprocesses exited unexpectedly:
  gcs_server [exit code=-11 (signal 11)]

[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474: *** SIGSEGV received at time=1781726136 on cpu 0 ***
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474: PC: @     0x55719802efb8  (unknown)  ray::gcs::RedisRequestContext::RedisResponseFn()
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474:     @     0x7f6c34fb6520  (unknown)  (unknown)
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474:     @     0x55719802f1f9       1168  ray::gcs::RedisRequestContext::Run()
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474:     @     0x55719801a748        224  ray::gcs::RedisStoreClient::AsyncCheckHealth()
```

---

## Update:
I first took the reconnect approach above, but a robust in-place
reconnect needs `Connect()` to be non-fatal (it `RAY_CHECK`s today, so a
transient failover still aborts `gcs_server`) - the larger refactor that
stalled ray-project#48781. So this PR instead takes the minimal fix: null-guard the
dereference so the request fails gracefully instead of crashing, and GCS
fault tolerance recovers as today. Full reconnect is left as a follow-up
(ray-project#48781).

Signed-off-by: Dongjun Na <[email protected]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
…ay-project#64204)

## Description

While testing, `gcs_server` crashed with a SIGSEGV during a Redis
connection error (failover). Looking for a fix I found ray-project#48781, which
solves it by reconnecting to Redis, but it was closed as stale without
being merged. Its main blocker at the time (a dependency cycle in the
GCS Redis client) has since been resolved by ray-project#49000 and ray-project#55655, so this
PR ports that reconnect approach onto the current version.

When the Redis connection is lost, an in-flight request retries against
the released connection and dereferences a null pointer, crashing the
GCS. This PR reconnects to Redis when the connection is dead so requests
retry on a healthy connection instead of crashing.

## Related issues

- Fixes ray-project#53475
- Based on ray-project#48781 by @MortalHappiness (closed without merge); credit for
the original design.

## Additional information

Reproduction:
1. Run a cluster with GCS fault tolerance backed by an HA Redis.
2. While the cluster is up, trigger a Redis primary failover e.g.
kill/replace the Redis primary so a replica is promoted.
3. Before this PR, `gcs_server` exits with signal 11 and the head pod
restarts; after this PR it reconnects to the new primary and continues.

The exact crash we observed:

```
2026-06-18 04:54:00,110 ERROR scripts.py:1219 -- Some Ray subprocesses exited unexpectedly:
  gcs_server [exit code=-11 (signal 11)]

[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474: *** SIGSEGV received at time=1781726136 on cpu 0 ***
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474: PC: @     0x55719802efb8  (unknown)  ray::gcs::RedisRequestContext::RedisResponseFn()
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474:     @     0x7f6c34fb6520  (unknown)  (unknown)
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474:     @     0x55719802f1f9       1168  ray::gcs::RedisRequestContext::Run()
[2026-06-18 04:55:36,551 E 42 42] (gcs_server) logging.cc:474:     @     0x55719801a748        224  ray::gcs::RedisStoreClient::AsyncCheckHealth()
```

---

## Update:
I first took the reconnect approach above, but a robust in-place
reconnect needs `Connect()` to be non-fatal (it `RAY_CHECK`s today, so a
transient failover still aborts `gcs_server`) - the larger refactor that
stalled ray-project#48781. So this PR instead takes the minimal fix: null-guard the
dereference so the request fails gracefully instead of crashing, and GCS
fault tolerance recovers as today. Full reconnect is left as a follow-up
(ray-project#48781).

Signed-off-by: Dongjun Na <[email protected]>
Signed-off-by: 400Ping <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-backlog go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants