Skip to content

Stability: Support calling redisAsyncCommand and redisAsyncDisconnect from the onConnected callback #931

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
merged 3 commits into from
Aug 19, 2022

Conversation

kristjanvalur
Copy link
Contributor

@kristjanvalur kristjanvalur commented Mar 26, 2021

There is nothing prevengint redisAsyncDisconnect() from being called from the onConnect() callback, and in fact, an application may decide that it doesn't want the connection.
However, redisAsyncDisconnect() will delete the context, before other processing involving the context can finish, when handling the original connection. This causes a crash.

This PR adds the usual callback flag when calling the connect/disconnect callbacks. Any pending disconnect or free is then handled by the __redisAsyncHandleConnect() handler.
It is now safe to delete the collection from the onConnect callback.

Additionally, the REDIS_CONNECTED flag is now set before the onConnect() callback is called, which makes the disconnect logic work correctly from with the callback.

In addition, any other redis commands can be called from the on_connected, such as redisAsyncCommand(), to directly schedule commands for execution.

The PR includes regression tests for both cases.

@kristjanvalur kristjanvalur changed the title Support calling redisAsyncDisconnect from the onConnected callback, Stability: Support calling redisAsyncDisconnect from the onConnected callback, Apr 8, 2021
@kristjanvalur
Copy link
Contributor Author

Simplified the change by leveraging the REDIS_IN_CALLBACK`` and REDIS_FREEING` flags when called for the connect/disconnect callbacks, and using helper functions to call them.

@kristjanvalur
Copy link
Contributor Author

Any news on this?

@kristjanvalur
Copy link
Contributor Author

It would be awesome to get any kind of feedback on this pull request.

kristjanvalur added a commit to kristjanvalur/hiredis that referenced this pull request Jul 8, 2022
@kristjanvalur
Copy link
Contributor Author

Rebased on top of main. Added regression test. Drop const qualifier on the redisAsyncContext in the connection callback, so that it can call api functions without warnings.

@kristjanvalur kristjanvalur changed the title Stability: Support calling redisAsyncDisconnect from the onConnected callback, Stability: Support calling redisAsyncCommand and redisAsyncDisconnect from the onConnected callback Jul 8, 2022
@kristjanvalur
Copy link
Contributor Author

Would be great to get a review on this. Adds parity to the onConnected callback so that other APIs can be called directly from it.

@michael-grunder michael-grunder merged commit 17c8fe0 into redis:master Aug 19, 2022
@kristjanvalur
Copy link
Contributor Author

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants