facebook / facebook/wangle

separate IOThreadPool for Echo example.

Open
#45 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
3.1k
Forks
547
PR merge metrics
No merged PRs in 30d

Description

trying to test the separate IOThreadPool. Patch like below for EchoClient.cpp
std::shared_ptrwangle::IOThreadPoolExecutor ioPool =
std::make_sharedwangle::IOThreadPoolExecutor(2);
std::shared_ptr pipeFact =
std::make_shared();

ClientBootstrap client;
client.group(ioPool);
client.pipelineFactory(pipeFact);

But when EchoClient exits, assert error showed up.
I0423 21:57:13.939635 54128 AsyncSocket.cpp:519] AsyncSocket::setReadCallback() this=0x7f2b88001950, fd=11, callback=0, state=2
EchoClient: io/async/AsyncSocket.cpp:558: virtual void folly::AsyncSocket::setReadCB(folly::AsyncTransportWrapper::ReadCallback*): Assertion `eventBase_->isInEventBaseThread()' failed.

Looks Pipeline/AsyncSocket destruction was called by the main thread, that was why AsyncSocket assert.

Added the patch to ClientBootstrap to avoid this assert. Is it the correct way to handle it?

Basically the patch kept the EventBase that was selected to setup the socket with server at connect() in ClientBootstrap class. And destruct pipeline in the EventBase thread in ~ClientBootstrap.
virtual ~ClientBootstrap() {
if (base_ && group_.get() && pipeline_) {
// Pipeline was already created, destroy from the EventBase thread
// as AsyncSocket destruct could only be called from its EventBase thread
VLOG(5) << " ~ClientBootstrap " << this
<< ", destruct pipeline_ in EventBase thread";
base_->runImmediatelyOrRunInEventBaseThreadAndWait([&](){
pipeline_.reset();
});
}
};

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.