ustcr7 opened a new issue #224: Get Transport timeout because of c++ try_lock_for fail spuriously URL: https://github.com/apache/rocketmq-client-cpp/issues/224 In our service, we found "get timed_mutex timeout" error log some times. We add some debug log and find this question is caused by c++ try_lock_for [fail spuriously](https://en.cppreference.com/w/cpp/thread/timed_mutex/try_lock_for) . ```cpp std::shared_ptr<TcpTransport> TcpRemotingClient::CreateTransport(const string& addr, bool needResponse) { std::shared_ptr<TcpTransport> tts; { // try get m_tcpLock util m_tcpTransportTryLockTimeout to avoid blocking // long time, if could not get m_tcpLock, return NULL std::unique_lock<std::timed_mutex> lock(m_tcpTableLock, std::try_to_lock); if (!lock.owns_lock()) { if (!lock.try_lock_for(std::chrono::seconds(m_tcpTransportTryLockTimeout))) { LOG_ERROR("GetTransport of:%s get timed_mutex timeout", addr.c_str()); std::shared_ptr<TcpTransport> pTcp; return pTcp; } } } ``` may be we can slove this question by a thread local cache or global cache with mutex。 Or use some concurrenty map just like what java client do: ```java private Channel getAndCreateChannel(final String addr) throws RemotingConnectException, InterruptedException { if (null == addr) { return getAndCreateNameserverChannel(); } ChannelWrapper cw = this.channelTables.get(addr); //just get from concurreny map without lock if (cw != null && cw.isOK()) { return cw.getChannel(); } return this.createChannel(addr); } ```
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
