Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

当服务器主动断开连接的时候,已连接的TCPClient资源和释放? #243

Open
aijyo opened this issue May 5, 2020 · 3 comments

Comments

@aijyo
Copy link

aijyo commented May 5, 2020

如题:
当服务器主动断开连接的时候,TCPClient OnConnection 函数中收到 Disconnecting的消息,
如果在这个事件之后调用Disconnect (在本次loop中调用,或QueueInLoop之后调用)函数的话,由于conn_已经断开连接了,不管这个时候conn_是否非空,在TCPClient::DisconnectInLoop中都会触发assert。如果不主动调用TCPClient::Disconnect的话,那么TCPClient 在析构的时候assert(!connector_.get()); 会触发。而connector_只能在TCPClient::DisconnectInLoop被重置为空。

所以问题是: 当服务器主动断开连接的时候,已连接的TCPClient资源和释放?

(TCPCLient的析构函数中的assert(!connector_.get()); 意味着必须调用TCPClient::Disconnect函数,而在服务器主动断开连接之后,客户端没法找到合适的时机去调用DisConnect函数,因为不管是在conn_ reset之前 还是 reset之后调用DisConnect都会在TCPClient::DisconnectInLoop中都会触发assert)

@Phymin
Copy link

Phymin commented Jun 12, 2020

顶一下,我们现在也遇到了类似的问题,希望有人解答一下

@aijyo
Copy link
Author

aijyo commented Jun 12, 2020

顶一下,我们现在也遇到了类似的问题,希望有人解答一下

我说下自己的解决方案吧,我最后改了evpp源码, tcp_client.cc文件, 大概是这两处地方,我目前在我自己使用的范围内没fa发现这个改动有啥大问题,你可以试试,还有就是这个框架基本上都是各种异步,建议自己业务相关的代码 多 enable_shared_from_this.
image

image

@Phymin
Copy link

Phymin commented Jun 12, 2020

我也去试试,谢谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants