facebook / facebook/folly

Coredump when another thread destroy

Open
#2,002 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
30.5k
Forks
5.9k
PR merge metrics
No merged PRs in 30d

Description

Thread 2 "async_client_te" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fe59836c700 (LWP 182469)]
0x00000000005441a0 in folly::ThreadLocalPtr, folly::RequestContext>::Wrapper, folly::RequestContext, void>::get (this=0x7fe5988e4230) at /_build/folly/folly/detail/ThreadLocalDetail.h:322
322 /_build/folly/folly/detail/ThreadLocalDetail.h: No such file or directory.
(gdb) bt
#0 0x00000000005441a0 in folly::ThreadLocalPtr, folly::RequestContext>::Wrapper, folly::RequestContext, void>::get (this=0x7fe5988e4230) at /_build/folly/folly/detail/ThreadLocalDetail.h:322
#1 folly::ThreadLocal, folly::RequestContext>::Wrapper, folly::RequestContext, void>::get (this=0x7fe5988e4230) at /_build/folly/folly/ThreadLocal.h:69
#2 folly::ThreadLocal, folly::RequestContext>::Wrapper, folly::RequestContext, void>::operator* (this=0x7fe5988e4230) at /_build/folly/folly/ThreadLocal.h:78
#3 folly::SingletonThreadLocal, folly::RequestContext>::getWrapper ()
at /_build/folly/folly/SingletonThreadLocal.h:138
#4 0x00000000005442c1 in folly::SingletonThreadLocal, folly::RequestContext>::LocalLifetime::~LocalLifetime (this=0x7fe598364fa0, __in_chrg=) at /_build/folly/folly/SingletonThreadLocal.h:128
#5 0x00000000005e8e56 in (anonymous namespace)::run(void*) ()
#6 0x00007fe59ed43ca2 in __nptl_deallocate_tsd () from /lib64/libpthread.so.0
#7 0x00007fe59ed43eb3 in start_thread () from /lib64/libpthread.so.0
#8 0x00007fe59d8da9fd in clone () from /lib64/libc.so.6

Soruce Code:

AsyncClient::AsyncClient(const std::string& ip, int port, int64_t t_out_ms) {
redisOptions options = {0};
REDIS_OPTIONS_SET_TCP(&options, "127.0.0.1", 6379);
struct timeval tv = {0};
tv.tv_sec = t_out_ms / 1000;
tv.tv_usec = (t_out_ms % 1000) * 1000;
options.connect_timeout = &tv;
async_ch_ = redisAsyncConnectWithOptions(&options);

if (async_ch_ == nullptr || async_ch_->err) {
std::cout << "connection error! \n";
redisAsyncFree(async_ch_);
}

base_ = event_base_new();
redisLibeventAttach(async_ch_, base_);
poll_ = std::thread(\[&]() {
std::cout << "[Thread] libevent: " << std::this_thread::get_id()
<< std::endl;
auto ret = event_base_dispatch(this->base_);
std::cout << "[State] libvent stop \n";
});
}

AsyncClient::~AsyncClient() {
redisAsyncDisconnect(async_ch_);
if (poll_.joinable()) poll_.join();
}

void AsyncClient::GetCallBack(redisAsyncContext* c, void* r, void* data) {
redisReply* resp = static_cast(r);
auto p = std::unique_ptr>(
static_cast*>(data));
std::cout << "[Thread] GetCallBak: " << std::this_thread::get_id()
<< std::endl;
if (resp == nullptr) {
p->setValue(GetResponse(Status::NotFound(), std::string("")));
return;
}
p->setValue(GetResponse(Status::OK(), std::string(resp->str)));
}

folly::Future\ AsyncClient::Get(const std::string& key) {
auto p = std::make_unique>();
folly::Future f = p->getFuture();
std::cout << "[Thread] FutureGet: " << std::this_thread::get_id()
<< std::endl;
std::unique_lock l(wlk_);
redisAsyncCommand(async_ch_, GetCallBack, p.release(), "GET %b", key.c_str(),
key.size());
return f;
}

Test code:
int main() {
AsyncClient apool("127.0.0.7", 6379);
auto f = apool.Set("folly_a", "async_test_value");
std::cout << "[Result] set : " << std::move(f).get().IsOK() << std::endl;
auto r = apool.Get("folly_a");
std::cout << "[Result] get: " << std::move(r).get().data << std::endl;

return 0;
}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.