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
async redis client segmentation fault upon brpop() if redis client connection is reconnected #1502
Comments
As a workaround I also tried the modified script which creates a brand new redis client instance instead of trying to reuse the last one and connect it again:
But it also has the same issue when redis server is restarted:
Interestingly with this version of the code then no segfault happens, just the unexpected error message. So it's a slight improvement. This makes me wonder if there is something weird going on with all the closure stuff? Any ideas? |
I have fixed this bug. When reconnecting need to set a timer, or the connection may be rejected because the redis server is starting. $redis_client->on("close", function(swoole_redis $redis_client) {
printf("%f - disconnected from redis by peer\n", microtime(true));
swoole_timer_after(2000, function () use ($redis_client) {
redis_connect($redis_client);
});
}); |
Thanks @matyhtf ! For other people interested in this redis client code. Here is some with a gentle redis retry using a single global 1,000 ms timer tick:
The the output when redis-server is restarted twice:
|
@matyhtf this also reminds me of another ticket I have open [1] because the tests don't run for me and other people. I'm guessing it's because there is environment setup that needs to be done before the tests are run, but this setup does not seem to be documented anywhere. And also, the tests do not test for whether the test environment is setup etc. This got me to thinking that perhaps the example code presented in this ticket would be useful as a new redis client test for reconnecting to a redis-server? On other projects I have worked on then it's standard policy to -- before fixing the bug, e.g. segfault -- create a failing test, then fix the bug, and then check that the new test is no longer failing. This helps in a few ways: Hopefully the bug never regresses because the test is now continually testing. And the test code itself acts as useful example code to new users of the library. Perhaps you and your fellow developers could adopt such a policy for swoole in the hopes that it will then become much more bullet proof over time in terms of quality? :-) [1] #1403 |
Please answer these questions before submitting your issue. Thanks!
An async redis client connects to redis using the following code which connects to redis, reconnects to redis if the connection is lost, upon connection does a redis brpop() with 5 second timeout, upon brpop() timeout does another brpop() with a 5 second timeout:
Unfortunately if e.g. redis server is restarted (sudo service redis-server restart) the next brpop() executed with the new redis connection causes the following segmentation fault:
No segmentation fault and just an error than brpop() cannot work if there is no redis connection.
The segfault.
php --ri swoole
)?No SSL.
The text was updated successfully, but these errors were encountered: