-
Notifications
You must be signed in to change notification settings - Fork 357
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
Connection Broken when ConnectionOptions::socket_timeout is set #49
Comments
I'm sorry, but this is a bug. The new version of hiredis has a new error code: This branch also fixed the other issue you opened earlier. Thanks a lot for finding these bugs! If you still have any problem, feel free to let me know :) Regards |
Hi, thanks for the response! |
Yes, this branch is stable, and pass all tests. I still need to add some code to ensure that this fix can work with older version of hiredis. When I finish that (this weekend), I'll merge the timeout branch into master. And the master branch is always stable. However, since I don't have MinGW environment, I cannot run tests on it. Could you please run these tests on MinGW, and give me some feedback? Thanks a lot! Regards |
I could try to run timeout-branch tests this weekend. If you could notify me when you will merge into master, I will port the new master into my project (I performed some changes in the files structure to meet my project requirements) and re-try the above code. OT: why do you decide to define callbacks with string passed by value and not reference? Ok for ownership (we could change the copied value) but, from my point of view, this is a lost of performance. Consider the case when we pass "stringify" values, such as profobuf or msgpack; these generally need a deserialization to obtain the desire object which generally makes a copy of the passed string. Why not decide to pass all by const reference and avoid the user to directly modify the string? |
I port your timeout branch changes into my code. Running this example now the Connection Broken problem seems ok!
OUTPUT:
It seems that the timeout fires always after 10 seconds and not milliseconds. MINGW TEST:Currently I was able to run only these tests since I'm under windows and I have Redis 4.x.
|
The I also did some research on this new error code. It seems hiredis only reports this error (connection timeout) on Windows platform. On Linux or macOS it still uses the old way to report timeout, i.e. Thanks again for your work! Regards |
There's no lost of performance, except an extra string move constructor, which is ignorable:
In this case, why we need to makes a copy of the passed string? You can just pass the received message to the parser of protobuf. Or I miss something?
Also, if you store protobuf into Redis, you can try redis-protobuf module, which can avoid serialization/deserialization on the client side, in some case. However, in the pub/sub case, you cannot avoid serialization/deserialization, since we can only publish or subscribe string values.
Because sometimes we need a copy of the message, for example:
In these cases, if the message is passed by const references, the user code has to make a copy of the message. Instead, if the message is passed by value, user code can move the message to avoid a copy. Also in the callback, since the message is owned by the user code, user can decide whether to modify it or not. Regards |
No, I didn't meet this problem on Linux or macOS. I run your program, and the output is:
I took a look at the hiredis code. It seems that it's a hiredis bug: in the net.c file, it convert
This seems right. However, net.c includes sockcompat.h, which defines
In
You can try the code, i.e. convert
You can just comment out the Regards |
Sorry, I closed this issue by accident. Now I reopen it. And please keep it open, until we solve all problems. Sorry again. Regards |
I run the following test code on macOs by defining
OUTPUT: 10000 Maybe we can open an issue or PR for hiredis. Regards |
Hi @sewenew , Damn! Yesterday I look in that specific code and I miss the bug! Your definition of Let me summarize the problem so that I can open the Issue on the hiredis repo: net.c
Line 320 a sockcompat.c
Line 215 casts I don't understand why the |
Nice work! |
Just to keep trace: now hiredis will be update soon fixing this bug (he simply removed lines 320, 321, 322, 323 from |
Hello, I´m having the same bad behavior running the same example in the version 1.3.1 with TLS connection options. If I run the example without TLS it runs as expected but if I run with TLS then I have this output:
Im using msvc 2015 environment. Thank you in advance. |
@labar90 I don't have a Windows box nearby, however, I tried the code with TLS on Linux, and cannot reproduce the problem. Also, please check the version of redis-plus-plus you used, the error message you gave in the comment, i.e. Failed to get reply: Unknown error code, has already been modified when I fixed this issue. It seems that you used an old version of redis-plus-plus. Please try the latest code to see if the problem still exists. Regards |
Yes, you are right. I copied the output from the previous message thinking it´s exactly the same output but my output is:
|
@Iabar90 What's version of hiredis did you use? The No error message should be reported by hiredis. However, I did some search with hiredis-1.0.0, and did not find No error (case matters) in the hiredis code. Regards |
@sewenew I am using hiredis v1.0.0 Regards. |
@Iabar90 I created a "debug" branch, which add some more error message when throwing error. Can you try the code on this debug branch, and give me the updated error message? So that I can do some debug on this problem. Thanks. Regards |
Hello @sewenew, I have tested the debug branch.
|
@Iabar90 Thanks for the info! It seems a bug of hiredis, which returns an IO error while the errno is 0. This should not happen. It seems that hiredis doesn't handle the SSL_read error properly. I'll do more digging.
Regrads |
Thank you so much @sewenew |
@Iabar90 I add some debug info for hiredis. However, the code works fine on both Linux and macOS. I cannot reproduce your problem. Can you try the modified hiredis in your Windows env? The modified code is on the master branch of https://github.com/sewenew/hiredis Please ensure that you uninstall the previously installed hiredis before install this modified version. If there're multiple versions of hiredis install, you'll get some wired problems. When you run the code, please give me the output of the code. It should print some ssl debug info to stderr, and some redis-plus-plus error on stdout. Please give both error messages. Thanks! Regards |
Hello @sewenew,
Regards and thanks. |
@sewenew I have just checked this new version and it does work. Thank you so much. |
@labar90 According to OpenSSL community, that’s a bug for OpenSSL 1.x. Can you upgrade OpenSSL to 3.0, and try the original version of hiredis? Thanks! Regards |
Hello @sewenew I have tested with OpenSSL 3.0 and it has the same wrong behaviour. It just works fine with your branch. Regards. |
@Iabar90 Can you also try the debug branch of redis-plus-plus I mentioned in the above comments, and hiredis version 1.0.0 (not the hiredis I modified) with OpenSSL 3.0, and give me the output of error messages? So that I can do more debug, and maybe ask the hiredis community to fix it. Thanks a lot! Regards |
Hello @sewenew , I have tested with redis-plus-plus debug and hiredis 1.0.0 and OpenSSL 3.0. The output is: Pass Regards. |
Hi, I'm have a problem with the
Subscriber
class when setting aConnectionOptions::socket_timeout
.Basic example:
All test are done voluntarily with no one publishing on that topics.
Without the explicit set of socket_timeout, all works as expected:
With the explicit set of socket_timeout (comment out the specific line), the output is:
[so on and so forth]
NOTE: the connection is broken after some seconds
In this case I would expect to see a TIMEOUT print, but no one is printed.
In my case, this behavior is 100% repeatable.
This error could be related to this modification? Am I missing something?
Thanks in advance!
The text was updated successfully, but these errors were encountered: