sewenew / redis-plus-plus

Redis client written in C++
Apache License 2.0
1.64k stars 351 forks source link

[BUG] crash in create redis ptr #605

Closed yushimeng closed 3 weeks ago

yushimeng commented 3 weeks ago

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_allocator::construct<sw::redis::ConnectionPool, sw::redis::ConnectionPoolOptions const&, sw::redis::ConnectionOptions const&> (

this=<optimized out>, __p=<optimized out>)
at /usr/aarch64-linux-gnu/include/c++/7/ext/new_allocator.h:136

2 std::allocator_traits<std::allocator >::construct<sw::redis::ConnectionPool, sw::redis::ConnectionPoolOptions const&, sw::redis::ConnectionOptions const&> (__a=...,

__p=<optimized out>) 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::allocator, 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_ptr::shared_ptr<std::allocator, sw::redis::ConnectionPoolOptions const&, sw::redis::ConnectionOptions const&> (a=..., tag=...,

this=<optimized out>) at /usr/aarch64-linux-gnu/include/c++/7/bits/shared_ptr.h:344

5 std::allocate_shared<sw::redis::ConnectionPool, std::allocator, 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_allocator::construct<sw::redis::Redis, sw::redis::ConnectionOptions&> (this=, p=0xaaaaab700990, pool_opts=..., connection_opts=...,

this=<optimized out>) at /opt/rtc/censor-stream/3rdparty/prefix/include/sw/redis++/redis.h:56

8 std::allocator_traits<std::allocator >::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::allocator, sw::redis::ConnectionOptions&> (a=..., tag=..., this=)

at /usr/aarch64-linux-gnu/include/c++/7/bits/shared_ptr_base.h:1327

10 std::shared_ptr::shared_ptr<std::allocator, 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::allocator, 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=<optimized out>, timeout=<optimized out>, expire=<optimized out>)
at /opt/rtc/censor-stream/src/rtc/redis_push.cpp:24

Environment:

Additional context Add any other context about the problem here.

sewenew commented 3 weeks ago

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

yushimeng commented 3 weeks ago

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