facebook / wangle

Wangle is a framework providing a set of common client/server abstractions for building services in a consistent, modular, and composable way.
Apache License 2.0
3.04k stars 536 forks source link

multiple connections to the same server with Echo example #38

Closed ghost closed 8 years ago

ghost commented 8 years ago

try to create multiple connections to the same server with Echo example. but could not get it work. any help?

The code change is simple

diff --git a/wangle/example/echo/EchoClient.cpp b/wangle/example/echo/EchoClient.cpp index 5ee0cad..2b424b1 100644 --- a/wangle/example/echo/EchoClient.cpp +++ b/wangle/example/echo/EchoClient.cpp @@ -60,26 +60,49 @@ int main(int argc, char\ argv) { google::ParseCommandLineFlags(&argc, &argv, true);

ClientBootstrap client; -- client.group(std::make_sharedwangle::IOThreadPoolExecutor(1)); ++ client.group(std::make_sharedwangle::IOThreadPoolExecutor(2)); client.pipelineFactory(std::make_shared()); auto pipeline = client.connect(SocketAddress(FLAGS_host, FLAGS_port)).get(); ++ auto pipeline1 = client.connect(SocketAddress(FLAGS_host, FLAGS_port)).get();

get below error ./bin/EchoClient -v=5 WARNING: Logging before InitGoogleLogging() is written to STDERR I0414 03:06:57.619832 12775 EventBase.cpp:164] EventBase(): Created. I0414 03:06:57.621055 12775 EventBase.cpp:295] EventBase(): Starting loop. I0414 03:06:57.621507 12775 EventBase.cpp:401] EventBase 0x7fd1e0000af0 loop time: 0 I0414 03:06:57.621940 12775 EventBase.cpp:401] EventBase 0x7fd1e0000af0 loop time: 0 I0414 03:06:57.622267 12775 EventBase.cpp:401] EventBase 0x7fd1e0000af0 loop time: 0 I0414 03:06:57.622627 12774 EventBase.cpp:164] EventBase(): Created. I0414 03:06:57.623005 12774 EventBase.cpp:295] EventBase(): Starting loop. I0414 03:06:57.623384 12773 EventBase.cpp:164] EventBase(): Created. I0414 03:06:57.623760 12774 EventBase.cpp:401] EventBase 0x7fd1d8000a10 loop time: 0 I0414 03:06:57.624092 12774 AsyncSocket.cpp:192] new AsyncSocket(0x7fd1d80017c0, evb=0x7fd1d8000a10) I0414 03:06:57.624151 12774 AsyncSocket.cpp:383] AsyncSocket::connect(this=0x7fd1d80017c0, evb=0x7fd1d8000a10, fd=15, host=[::1]:8080 I0414 03:06:57.624732 12774 EventBase.cpp:401] EventBase 0x7fd1d8000a10 loop time: 0 I0414 03:06:57.624949 12774 AsyncSocket.cpp:1401] AsyncSocket::handleWrite() this=0x7fd1d80017c0, fd=15, state=1 I0414 03:06:57.624963 12774 AsyncSocket.cpp:1573] AsyncSocket::handleConnect() this=0x7fd1d80017c0, fd=15, state=1 I0414 03:06:57.624979 12774 AsyncSocket.cpp:1750] AsyncSocket::updateEventRegistration(this=0x7fd1d80017c0, fd=15, evb=0x7fd1d8000a10, state=2, events=2 I0414 03:06:57.625022 12775 AsyncSocket.cpp:192] new AsyncSocket(0x7fd1e0001950, evb=0x7fd1e0000af0) I0414 03:06:57.625051 12775 AsyncSocket.cpp:383] AsyncSocket::connect(this=0x7fd1e0001950, evb=0x7fd1e0000af0, fd=16, host=[::1]:8080 EchoClient: io/async/AsyncSocket.cpp:558: virtual void folly::AsyncSocket::setReadCB(folly::AsyncTransportWrapper::ReadCallback*): Assertion `eventBase_->isInEventBaseThread()' failed. Aborted

ghost commented 8 years ago

If connect to 2 servers, looks the first connection is closed? Does this mean wangle could NOT share IOThreadPool among connections?

diff --git a/wangle/example/echo/EchoClient.cpp b/wangle/example/echo/EchoClient.cpp index 5ee0cad..5f101ee 100644 --- a/wangle/example/echo/EchoClient.cpp +++ b/wangle/example/echo/EchoClient.cpp @@ -63,23 +63,46 @@ int main(int argc, char\ argv) { client.group(std::make_sharedwangle::IOThreadPoolExecutor(1)); client.pipelineFactory(std::make_shared()); auto pipeline = client.connect(SocketAddress(FLAGS_host, FLAGS_port)).get(); ++ auto pipeline1 = client.connect(SocketAddress(FLAGS_host, 8070)).get();

./bin/EchoClient -v=5 WARNING: Logging before InitGoogleLogging() is written to STDERR I0414 03:18:42.539069 13215 EventBase.cpp:164] EventBase(): Created. I0414 03:18:42.540269 13215 EventBase.cpp:295] EventBase(): Starting loop. I0414 03:18:42.540786 13214 EventBase.cpp:164] EventBase(): Created. I0414 03:18:42.541205 13215 EventBase.cpp:401] EventBase 0x7f6910000af0 loop time: 0 I0414 03:18:42.541543 13215 AsyncSocket.cpp:192] new AsyncSocket(0x7f6910001950, evb=0x7f6910000af0) I0414 03:18:42.541913 13215 AsyncSocket.cpp:383] AsyncSocket::connect(this=0x7f6910001950, evb=0x7f6910000af0, fd=11, host=[::1]:8080 I0414 03:18:42.575080 13215 EventBase.cpp:401] EventBase 0x7f6910000af0 loop time: 33 I0414 03:18:42.575783 13215 AsyncSocket.cpp:1401] AsyncSocket::handleWrite() this=0x7f6910001950, fd=11, state=1 I0414 03:18:42.576248 13215 AsyncSocket.cpp:1573] AsyncSocket::handleConnect() this=0x7f6910001950, fd=11, state=1 I0414 03:18:42.576648 13215 AsyncSocket.cpp:1750] AsyncSocket::updateEventRegistration(this=0x7f6910001950, fd=11, evb=0x7f6910000af0, state=2, events=2 I0414 03:18:42.576925 13215 EventBase.cpp:401] EventBase 0x7f6910000af0 loop time: 1 I0414 03:18:42.576954 13215 AsyncSocket.cpp:192] new AsyncSocket(0x7f69100022f0, evb=0x7f6910000af0) I0414 03:18:42.577000 13215 AsyncSocket.cpp:383] AsyncSocket::connect(this=0x7f69100022f0, evb=0x7f6910000af0, fd=12, host=[::1]:8070 I0414 03:18:42.577679 13215 AsyncSocket.cpp:1750] AsyncSocket::updateEventRegistration(this=0x7f6910001950, fd=11, evb=0x7f6910000af0, state=2, events=0 I0414 03:18:42.577715 13215 AsyncSocket.cpp:250] AsyncSocket::destroy(this=0x7f6910001950, evb=0x7f6910000af0, fd=11, state=2 I0414 03:18:42.577729 13215 AsyncSocket.cpp:812] AsyncSocket::closeNow(): this=0x7f6910001950, fd_=11, state=2, shutdownFlags=0 I0414 03:18:42.577813 13215 EventBase.cpp:401] EventBase 0x7f6910000af0 loop time: 0 I0414 03:18:42.578115 13215 AsyncSocket.cpp:1401] AsyncSocket::handleWrite() this=0x7f69100022f0, fd=12, state=1 I0414 03:18:42.578132 13215 AsyncSocket.cpp:1573] AsyncSocket::handleConnect() this=0x7f69100022f0, fd=12, state=1 I0414 03:18:42.578147 13215 AsyncSocket.cpp:1750] AsyncSocket::updateEventRegistration(this=0x7f69100022f0, fd=12, evb=0x7f6910000af0, state=2, events=2 I0414 03:18:42.578207 13215 EventBase.cpp:401] EventBase 0x7f6910000af0 loop time: 0 I0414 03:18:48.651737 13215 EventBase.cpp:401] EventBase 0x7f6910000af0 loop time: 6073 1 Segmentation fault

ghost commented 8 years ago

It turned out to be a misuse. When ClientBootstrap sets up the second connection, the original pipeline will be automatically destroyed, as ClientBootstrap.connect returns future(Pipeline*), not share_ptr.

Has to create two ClientBootstrap instances.