Nordix / hiredis-cluster

C client library for Valkey/Redis Cluster. This project is used and sponsored by Ericsson. It is a fork of the now unmaintained hiredis-vip.
BSD 3-Clause "New" or "Revised" License
87 stars 42 forks source link

Asynchronously connect to the initial node #169

Closed bjosv closed 1 year ago

bjosv commented 1 year ago

Replace the initial blocking connect in redisClusterAsyncConnect() with an ad hoc connect and slotmap update. redisClusterAsyncConnect() only creates an asynchronous context with a prepared slot map containing configured nodes.

Since this API is called before any event system can be attached (which is needed for async) there is no immediate connection establishment performed. Users of this API is required to attach an event engine adapter to the returned cluster context and then any sent command will trigger the connection attempt. The prepared slot map will probably not match Redis view but Redis will make sure that hiredis-cluster's slotmap is updated via a MOVED redirect.

Before this change a blocking connect was setup during the API call and the slotmap was updated before returning.

Example usage of redisClusterAsyncConnect(): https://github.com/Nordix/hiredis-cluster/blob/1482d2147eed3e8b9774425491f0b1167d007644/tests/ct_async.c#L36C1-L51

Seems to trigger new interesting heap-use-after-free in the ct_async_glib test only...

bjosv commented 1 year ago

Conclusion is to keep current behavior as some users might rely on it.