Skip to content
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

[QUESTION] When I create a sentinel of redis-plus-plus, an exception is raised #342

Closed
silvertranks opened this issue Mar 17, 2022 · 11 comments

Comments

@silvertranks
Copy link

silvertranks commented Mar 17, 2022

Describe the problem

I am trying to use the redis sentinel function.
When I create a sentinel of redis-plus-plus, an exception is raised.

Exception occurs when Sentinel is created as shown in the code below.
image

Exceptions are as follows.
image

Please check.

Environment:

  • OS: windows7
  • Compiler: visual studio 2022 / unicode
  • hiredis version: master (date: 2022-2-2 2:10, commit:f8de9a4)
  • redis-plus-plus version: master (date: 2022-2-8 23:30, commit:244e8cb)
  • c++ version : 17

Additional context
Add any other context about the problem here.

@sewenew
Copy link
Owner

sewenew commented Mar 17, 2022

Since redis-plus-plus might throw exceptions, you should always try-catch possible exceptions in your code.

try {
    // redis-plus-plus related code.
} catch (const Error &e) {
   cerr << e.what() << end;    // <----- error message.
}

Please show me the error message of the exception. So that I can be more helpful.

Regards

@silvertranks
Copy link
Author

Thank you for the reply @sewenew .
I implemented a try catch statement as you said.
But it doesn't enter the catch statement.
Is there anything else I should do to solve the problem?
image

@silvertranks
Copy link
Author

I will go back to the beginning and try again from hiredis cmake build to redis-plus-plus cmake build.

@silvertranks
Copy link
Author

silvertranks commented Mar 18, 2022

Thanks for your interest in my problem@sewenew.
Going back to the beginning, after git clone Hiredis/Redis-plus-plus master,
I built each with CMake.
And I tested single redis to see if it works normally from Hiredis, and it worked.
image

But in Redis-plus-plus, even basic single redis does not work as shown in the screenshot below.
image

The development environment is still the same.
Using Redis sentinel is very important to the development of our project. Please help me. thank you.

@sewenew
Copy link
Owner

sewenew commented Mar 18, 2022

You got a bad_alloc, which means the program cannot allocate memory on heap. Normally that's should not happen, unless your system is out-of-memory.

I cannot reproduce your problem with Win 10 and Visual Studio 2019. It seems that you might not install redis-plus-plus correctly. Please try to recompile redis-plus-plus and reinstall it.

I'm not familiar with Visual Studio, but you might need to check the Configuration Manager, if those options, e.g. x64-Release, match for hiredis, redis-plus-plus, and your application code.

Regards

@silvertranks
Copy link
Author

I will try again.
Thank you @sewenew

@sewenew
Copy link
Owner

sewenew commented Mar 26, 2022

Since there's no update, I'll close this issue.

Regards

@sewenew sewenew closed this as completed Mar 26, 2022
@MrStack
Copy link

MrStack commented Apr 2, 2022

Hello, I think I ran into the same problem under Linux system.

the source code:

int main(void)
{
sw::redis::SentinelOptions sentinel_ops;
sentinel_ops.nodes = {{"127.0.0.1", 26379}};
sentinel_ops.connect_timeout = std::chrono::milliseconds(200);
sentinel_ops.socket_timeout = std::chrono::milliseconds(200);

auto sp_sentinel = std::make_shared<sw::redis::Sentinel>(sentinel_ops);

return 0;

}

gdb tells:
Program received signal SIGSEGV, Segmentation fault.
__GI___libc_free (mem=0x2e302e302e373231) at malloc.c:3102
3102 malloc.c: No such file or directory.
(gdb) bt
#0 __GI___libc_free (mem=0x2e302e302e373231) at malloc.c:3102
#1 0x000055555556726e in sw::redis::tls::TlsOptions::~TlsOptions() ()
#2 0x00005555555672a0 in sw::redis::ConnectionOptions::ConnectionOptions() ()
#3 0x0000555555569570 in void __gnu_cxx::new_allocator<std::_List_nodesw::redis::ConnectionOptions >::destroysw::redis::ConnectionOptions(sw::redis::ConnectionOptions*) ()
#4 0x00005555555694a3 in void std::allocator_traits<std::allocator<std::_List_nodesw::redis::ConnectionOptions > >::destroysw::redis::ConnectionOptions(std::allocator<std::_List_nodesw::redis::ConnectionOptions >&, sw::redis::ConnectionOptions*) ()
#5 0x00005555555693a6 in std::__cxx11::_List_base<sw::redis::ConnectionOptions, std::allocatorsw::redis::ConnectionOptions >::_M_clear() ()
#6 0x0000555555569282 in std::__cxx11::_List_base<sw::redis::ConnectionOptions, std::allocatorsw::redis::ConnectionOptions >::
_List_base() ()
#7 0x00005555555691aa in std::__cxx11::list<sw::redis::ConnectionOptions, std::allocatorsw::redis::ConnectionOptions >::list() ()
#8 0x00005555555691da in sw::redis::Sentinel::Sentinel() ()
#9 0x0000555555569206 in void __gnu_cxx::new_allocatorsw::redis::Sentinel::destroysw::redis::Sentinel(sw::redis::Sentinel*) ()
#10 0x0000555555569165 in void std::allocator_traits<std::allocatorsw::redis::Sentinel >::destroysw::redis::Sentinel(std::allocatorsw::redis::Sentinel&, sw::redis::Sentinel*) ()
#11 0x0000555555569055 in std::_Sp_counted_ptr_inplace<sw::redis::Sentinel, std::allocatorsw::redis::Sentinel, (__gnu_cxx::_Lock_policy)2>::_M_dispose() ()
#12 0x0000555555567953 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() ()
#13 0x00005555555675f9 in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::
__shared_count() ()
#14 0x0000555555567368 in std::__shared_ptr<sw::redis::Sentinel, (__gnu_cxx::_Lock_policy)2>::
__shared_ptr() ()
#15 0x0000555555567384 in std::shared_ptrsw::redis::Sentinel::~shared_ptr() ()
#16 0x0000555555567063 in main ()

Environment:

OS: Linux debian 5.10.0-9-amd64 #1 SMP Debian 5.10.70-1 (2021-09-30) x86_64 GNU/Linux
Compiler: g++ (Debian 10.2.1-6) 10.2.1 20210110
hiredis version: master (date: 2022-2-2 2:10, commit:f8de9a4)
redis-plus-plus version: 1.3.3
c++ version : 11

Something goes wrong in the destructer of ~ConnectionOptions()?

@sewenew
Copy link
Owner

sewenew commented Apr 3, 2022

@MrStack I cannot reproduce the problem with the code you given. The destructor of ConnectionOptions is quite simply, since it only contains some built-in types and STL types as data member.

Also, please check if you installed multiple version of hiredis? If you do, you might get some wired problems.

Regards

@MrStack
Copy link

MrStack commented Apr 11, 2022

I think I know what the problem is. Maybe something goes wrong with the tls. I just substitude the no_tls/tls.h when the compiler complains, then the error vanished.

@sewenew
Copy link
Owner

sewenew commented Apr 11, 2022

@MrStack When building redis-plus-plus, did you enabled TLS support? If you did, you should build hiredis with TLS support, and linking your application code with both libhiredis and libhiredis_ssl. Otherwise, the behavior is undefined.

I just substitude the no_tls/tls.h when the compiler complains, then the error vanished.

no_tls/tls.h is used when TLS is disabled, otherwise, tls/tls.h is used.

Regards

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

No branches or pull requests

3 participants