You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
EventHandler not work after use eb->runInEventBaseThread #35
In Duplex Server. I use server->setServerEventHandler function to add a EventHandler. I want to do some work after a connection destroyed. But if I use eb->runInEventBaseThread to push a msg to the client, the EventHandler will not work after that(maybe after the HeaderClientChannel::sendRequest is called). How can I make it work?
When you say 'Duplex server', do you mean one set up with ->setDuplex(true)?
Are you running eb->runInEventBaseThread on the server-side server or on the client-side server? Can you provide some example code showing what you are doing and what is not working?
classTestServerInterface : publicTestServerSvIf {
voidasync_tm_test(std::unique_ptr<apache::thrift::HandlerCallback<bool>> callback,
int64_t id) override {
auto callbackp = callback.release();
auto ctx = callbackp->getConnectionContext()->getConnectionContext();
auto client = ctx->getDuplexClient<DuplexClientAsyncClient>();
auto eb = callbackp->getEventBase();
eb->runInEventBaseThread([=]() mutable {
client->test_someting([](ClientReceiveState&& state) {
bool res = TestClientAsyncClient::recv_test_something(state);
}, "teststr");
});
callbackp->resultInThread(true);
}
};
classTestServerEventHandler
: public server::TServerEventHandler
, public TProcessorEventHandler
, public TProcessorEventHandlerFactory
, public std::enable_shared_from_this<TestServerEventHandler> {
public:
std::shared_ptr<TProcessorEventHandler> getEventHandler() {
returnshared_from_this();
}
voidconnectionDestroyed(TConnectionContext* ctx) {
std::cout << "aaaaaaa" << std::endl;
}
};
// create a server .......
server->setDuplex(true);
server->setInterface(std::unique_ptr<TestServerInterface>(new TestServerInterface));
auto serverHandler = std::make_shared<TestServerEventHandler>();
TProcessorBase::addProcessorEventHandlerFactory(serverHandler);
server->setServerEventHandler(serverHandler);
server->serve();
I set a event handler and print "aaaa" when a connection destroyed. But I found that if a client connected and run the server's "async_tm_test" function, then the client close the connection, the TestServerEventHandler will not work, no "aaaa" printed.
Now, I use this code : (I defined a new callback and setCloseCallback in function "async_tm_test")
When the client close the connection, the new callback function works.
So I don't know what is the difference between "server->setServerEventHandler" and "client->getChannel()->setCloseCallback", and why the setServerEventHandler doesn't work before.
Thanks for the detailed description. I was able to repro and fix.
The issue was that the server didn't close the connection when the client closed (so it remained half-open). Since the server's end of the connection remained open, the connectionDestroyed() event didn't fire. It would fire after an idle timeout though. I fixed this and it should appear on github at the next sync.
As for setCloseCallback(), it is firing on the client. Since the client DID close its end of the connection, the event was firing.
Activity
alandau commentedon Sep 29, 2014
When you say 'Duplex server', do you mean one set up with ->setDuplex(true)?
Are you running eb->runInEventBaseThread on the server-side server or on the client-side server? Can you provide some example code showing what you are doing and what is not working?
junstor commentedon Sep 30, 2014
This is my example code :
I set a event handler and print "aaaa" when a connection destroyed. But I found that if a client connected and run the server's "async_tm_test" function, then the client close the connection, the TestServerEventHandler will not work, no "aaaa" printed.
Now, I use this code : (I defined a new callback and setCloseCallback in function "async_tm_test")
When the client close the connection, the new callback function works.
So I don't know what is the difference between "server->setServerEventHandler" and "client->getChannel()->setCloseCallback", and why the setServerEventHandler doesn't work before.
Thanks.
alandau commentedon Sep 30, 2014
Thanks for the detailed description. I was able to repro and fix.
The issue was that the server didn't close the connection when the client closed (so it remained half-open). Since the server's end of the connection remained open, the connectionDestroyed() event didn't fire. It would fire after an idle timeout though. I fixed this and it should appear on github at the next sync.
As for setCloseCallback(), it is firing on the client. Since the client DID close its end of the connection, the event was firing.
alandau commentedon Oct 1, 2014
Fixed in 4f8a83c
thrift/lib/cpp2/test/StreamingTest.cpp: fix SIOF bug and heap-use-aft…
Fix TMemoryBuffer::ensureCanWrite
Add e2e regression test for Cpp2Channel::writeError upgrade-teardown UAF