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();
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();
});
}
};
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(); }); } };