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

[BUG] crash in create redis ptr #605

Closed
yushimeng opened this issue Oct 25, 2024 · 2 comments
Closed

[BUG] crash in create redis ptr #605

yushimeng opened this issue Oct 25, 2024 · 2 comments

Comments

@yushimeng
Copy link

Describe the bug
在线上容器内编译生成的程序运行正常, 但是本地交叉编译后放在线上容器内运行崩溃.
线上宿主机arm centos, 容器 ubuntu,

To Reproduce
#include
#include
#include
#include <sw/redis++/redis++.h>

using namespace std;
using namespace sw::redis;

int redis_test() {
ConnectionOptions connection_options;
connection_options.host = "172.18.10.7"; // Required.
connection_options.port = 6301; // Optional. The default port is 6379.
connection_options.password = "7Un9oVRyVZ"; // Optional. No password by default.
connection_options.db = 0; // Optional. Use the 0th database by default.

// Optional. Timeout before we successfully send request to or receive response from redis.
// By default, the timeout is 0ms, i.e. never timeout and block until we send or receive successfuly.
// NOTE: if any command is timed out, we throw a TimeoutError exception.
connection_options.socket_timeout = std::chrono::milliseconds(0);

shared_ptr<Redis> redis_;
try
{
   redis_ = std::make_shared<Redis>(connection_options);
}
catch(const std::exception& e)
{
    std::cerr << e.what() << '\n';
}
if (redis_ == nullptr) {
    cout << "failed to alloc redis" << endl;
    return -1;
}
cout << "run sucess..." << endl;
return 0;

// Connect to Redis server with a single connection.
// Redis redis1(connection_options);

}
Expected behavior
crash :
(gdb) bt
#0 0x0000aaaaab41f020 in sw::redis::ConnectionPool::ConnectionPool(sw::redis::ConnectionPoolOptions const&, sw::redis::ConnectionOptions const&) ()
#1 0x0000aaaaaac0933c in __gnu_cxx::new_allocatorsw::redis::ConnectionPool::construct<sw::redis::ConnectionPool, sw::redis::ConnectionPoolOptions const&, sw::redis::ConnectionOptions const&> (
this=, __p=)
at /usr/aarch64-linux-gnu/include/c++/7/ext/new_allocator.h:136
#2 std::allocator_traits<std::allocatorsw::redis::ConnectionPool >::construct<sw::redis::ConnectionPool, sw::redis::ConnectionPoolOptions const&, sw::redis::ConnectionOptions const&> (__a=...,
__p=) at /usr/aarch64-linux-gnu/include/c++/7/bits/alloc_traits.h:475
#3 std::__shared_ptr<sw::redis::ConnectionPool, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocatorsw::redis::ConnectionPool, sw::redis::ConnectionPoolOptions const&, sw::redis::ConnectionOptions const&> (__a=..., __tag=..., this=)
at /usr/aarch64-linux-gnu/include/c++/7/bits/shared_ptr_base.h:1327
#4 std::shared_ptrsw::redis::ConnectionPool::shared_ptr<std::allocatorsw::redis::ConnectionPool, sw::redis::ConnectionPoolOptions const&, sw::redis::ConnectionOptions const&> (__a=..., __tag=...,
this=) at /usr/aarch64-linux-gnu/include/c++/7/bits/shared_ptr.h:344
#5 std::allocate_shared<sw::redis::ConnectionPool, std::allocatorsw::redis::ConnectionPool, sw::redis::ConnectionPoolOptions const&, sw::redis::ConnectionOptions const&> (__a=...)
at /usr/aarch64-linux-gnu/include/c++/7/bits/shared_ptr.h:691
#6 std::make_shared<sw::redis::ConnectionPool, sw::redis::ConnectionPoolOptions const&, sw::redis::ConnectionOptions const&> () at /usr/aarch64-linux-gnu/include/c++/7/bits/shared_ptr.h:707
#7 __gnu_cxx::new_allocatorsw::redis::Redis::construct<sw::redis::Redis, sw::redis::ConnectionOptions&> (this=, __p=0xaaaaab700990, pool_opts=..., connection_opts=...,
this=) at /opt/rtc/censor-stream/3rdparty/prefix/include/sw/redis++/redis.h:56
#8 std::allocator_traits<std::allocatorsw::redis::Redis >::construct<sw::redis::Redis, sw::redis::C---Type to continue, or q to quit---
onnectionOptions&> (__a=..., __p=0xaaaaab700990)
at /usr/aarch64-linux-gnu/include/c++/7/bits/alloc_traits.h:475
#9 std::__shared_ptr<sw::redis::Redis, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocatorsw::redis::Redis, sw::redis::ConnectionOptions&> (__a=..., __tag=..., this=)
at /usr/aarch64-linux-gnu/include/c++/7/bits/shared_ptr_base.h:1327
#10 std::shared_ptrsw::redis::Redis::shared_ptr<std::allocatorsw::redis::Redis, sw::redis::ConnectionOptions&> (__a=..., __tag=..., this=)
at /usr/aarch64-linux-gnu/include/c++/7/bits/shared_ptr.h:344
#11 std::allocate_shared<sw::redis::Redis, std::allocatorsw::redis::Redis, sw::redis::ConnectionOptions&> (__a=...) at /usr/aarch64-linux-gnu/include/c++/7/bits/shared_ptr.h:691
#12 std::make_shared<sw::redis::Redis, sw::redis::ConnectionOptions&> ()
at /usr/aarch64-linux-gnu/include/c++/7/bits/shared_ptr.h:707
#13 RedisPush::RedisPush (this=0xaaaaab70afc0, host=..., port=, password=...,
db=, timeout=, expire=)
at /opt/rtc/censor-stream/src/rtc/redis_push.cpp:24

Environment:

  • OS: ubuntu Linux bare-mx-01 4.19.90-2102.2.0.0062.ctl2.aarch64 add socket library depency on SunOS platform #1 SMP Thu Mar 10 03:30:47 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux
  • Compiler: 交叉编译
  • hiredis version: master commit ID: 7ab6b824c771df8298cbe1b512a80116d005ec33
  • redis-plus-plus version: master commit ID: fe6e72f

Additional context
Add any other context about the problem here.

@sewenew
Copy link
Owner

sewenew commented Oct 27, 2024

抱歉,我对交叉编译不是很了解,之前没试过通过交叉编译来安装redis-plus-plus。从你的这个堆栈信息来看,似乎在创建ConnectionPool的时候出问题了(这个堆栈信息也没有看出有访问空指针之类的问题),但这个类的构造函数只是对数据乘员的拷贝初始化,没有其它操作,应该不会有问题。感觉像是交叉编译导致了一些内存问题。你可以试试交叉编译一个与redis-plus-plus无关的,但存在shared_ptr和自定义类的程序,看看是不是交叉编译指令的问题。

@yushimeng
Copy link
Author

可能是依赖库的问题, 我重新编译hiredis和redisplusplus, 符合预期, 不崩溃了.

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

2 participants