This is an automated email from the ASF dual-hosted git repository. ifplusor pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/rocketmq-client-cpp.git
The following commit(s) were added to refs/heads/master by this push: new c7777af fix: connect concurrently failed (#451) c7777af is described below commit c7777af437156841ba2f15d004d0aa0a16d4b4e6 Author: yuz10 <845238...@qq.com> AuthorDate: Fri Oct 6 15:48:24 2023 +0800 fix: connect concurrently failed (#451) --- src/transport/TcpRemotingClient.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/transport/TcpRemotingClient.cpp b/src/transport/TcpRemotingClient.cpp index fa2bfc8..a077406 100644 --- a/src/transport/TcpRemotingClient.cpp +++ b/src/transport/TcpRemotingClient.cpp @@ -319,8 +319,7 @@ std::shared_ptr<TcpTransport> TcpRemotingClient::CreateTransport(const string& a if (connectStatus == TCP_CONNECT_STATUS_SUCCESS) { return tcp; } else if (connectStatus == TCP_CONNECT_STATUS_WAIT) { - std::shared_ptr<TcpTransport> pTcp; - return pTcp; + tts = tcp; } else if (connectStatus == TCP_CONNECT_STATUS_FAILED) { LOG_ERROR("tcpTransport with server disconnected, erase server:%s", addr.c_str()); tcp->disconnect(addr); // avoid coredump when connection with broker was broken @@ -334,17 +333,18 @@ std::shared_ptr<TcpTransport> TcpRemotingClient::CreateTransport(const string& a //<!callback; TcpTransportReadCallback callback = needResponse ? &TcpRemotingClient::static_messageReceived : nullptr; - - tts = TcpTransport::CreateTransport(this, m_enableSsl, m_sslPropertyFile, callback); - TcpConnectStatus connectStatus = tts->connect(addr, 0); // use non-block - if (connectStatus != TCP_CONNECT_STATUS_WAIT) { - LOG_WARN("can not connect to:%s", addr.c_str()); - tts->disconnect(addr); - std::shared_ptr<TcpTransport> pTcp; - return pTcp; - } else { - // even if connecting failed finally, this server transport will be erased by next CreateTransport - m_tcpTable[addr] = tts; + if (!tts) { + tts = TcpTransport::CreateTransport(this, m_enableSsl, m_sslPropertyFile, callback); + TcpConnectStatus connectStatus = tts->connect(addr, 0); // use non-block + if (connectStatus != TCP_CONNECT_STATUS_WAIT) { + LOG_WARN("can not connect to:%s", addr.c_str()); + tts->disconnect(addr); + std::shared_ptr<TcpTransport> pTcp; + return pTcp; + } else { + // even if connecting failed finally, this server transport will be erased by next CreateTransport + m_tcpTable[addr] = tts; + } } }