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
CPP2 Out of order responses with THeader "not" working #52
I have been trying for a while to get out of order responses to work with THeader protocol using cpp2::ThriftServer and a cpp2 client. I created an echo server deriving from cpp2::ThriftServer which uses THeaderProtocolFactory and THeaderTransportFactory by manually setting them.
Then I fired up a cpp2 client to send requests to the server and the server echoes back the requests. The client uses the HeaderClientChannel::newChannel. When I use the sync method of the client within a single thread, everything works fine. However, the moment I use the async method, it breaks down. I created a separate client worker thread with an eventbase to which my TAsyncSocket is attached. I am running the following in my main thread. The evb is the eventbase associated with the client worker thread.
for (int i = 0; i < 1000; i++) {
evb->runInEventBaseThread(&{
client.ping(unique_ptr(new Callback(i)), to_string(i));
});
}
I am getting garbled up responses and eventually get a core dump stating that at some point the event base was accessed by a thread which should not touch the event base. I would highly appreciate if you guys could point out where I am configuring my client incorrectly. Any examples on how to use a cpp2 server + cpp2 client with out of order responses would be highly appreciated. Otherwise, we need to implement a socket pool etc.
Thanks for the clarification. I removed those instantiations as you mentioned. In my client, I also made sure that all the TAsyncSocket operations including init are happening in the event base thread which is separate from the main thread. My ThriftServer initialization looks like the following. Note that there is a "handler" variable which belongs to a handler implementing the "Ping" call which echoes back the string:
unique_ptr handler(new PingHandler);
shared_ptrapache::thrift::ThriftServer server(new
apache::thrift::ThriftServer);
cout << "Server created..";
handler->setServer(server.get());
server->setInterface(unique_ptr(handler.release()));
server->setPort(port);
cout << "Serving at port " << port << endl;
server->serve();
Now, when I run the client against this server in async mode using a single connection - I get "Channel is !good" and the requestError() function in my RequestCallback is being invoked. The socket is getting created which means that the connection is going through. Is there something else I am missing - the example you gave contains some things around building/passing a ThreadManager but I thought that wont be necessary and that we would use one EventBase for accepting and Cpp2Workers (as many as cores) for running the calls in an event driven fashion. Any help would be really appreciated..
Activity
alandau commentedon Dec 1, 2014
Out of order is on by default for a cpp2 client + cpp2 server, you don't have to do anything to enable it. There are examples in unittests, e.g. https://github.com/facebook/fbthrift/blob/master/thrift/lib/cpp2/test/ThriftServerTest.cpp
THeaderProtocolFactory and THeaderTransportFactory are cpp1 classes, you don't need to use them. Perhaps the crashes are exactly because of this.
varunsharmagit commentedon Dec 2, 2014
Thanks for the clarification. I removed those instantiations as you mentioned. In my client, I also made sure that all the TAsyncSocket operations including init are happening in the event base thread which is separate from the main thread. My ThriftServer initialization looks like the following. Note that there is a "handler" variable which belongs to a handler implementing the "Ping" call which echoes back the string:
unique_ptr handler(new PingHandler);
shared_ptrapache::thrift::ThriftServer server(new
apache::thrift::ThriftServer);
cout << "Server created..";
handler->setServer(server.get());
server->setInterface(unique_ptr(handler.release()));
server->setPort(port);
cout << "Serving at port " << port << endl;
server->serve();
Now, when I run the client against this server in async mode using a single connection - I get "Channel is !good" and the requestError() function in my RequestCallback is being invoked. The socket is getting created which means that the connection is going through. Is there something else I am missing - the example you gave contains some things around building/passing a ThreadManager but I thought that wont be necessary and that we would use one EventBase for accepting and Cpp2Workers (as many as cores) for running the calls in an event driven fashion. Any help would be really appreciated..
varunsharmagit commentedon Dec 2, 2014
Seems like there was another issue - I tested the duplex pipeline with multiple threads and it works ! Thanks !