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 crashed when DNS resolving timeout #43

Closed
zieckey opened this issue May 10, 2017 · 0 comments
Closed

TCPClient crashed when DNS resolving timeout #43

zieckey opened this issue May 10, 2017 · 0 comments
Labels

Comments

@zieckey
Copy link
Collaborator

zieckey commented May 10, 2017

Steps:

  1. Set the DNS server to a far way server of the local mathine, we set it to 8.8.8.8 in China
  2. Set the TCPClient connection timeout to a very small duration, like 1ms

Result:

  1. Connector will timeout at first and call Connector::HandleError
  2. And then, DNSResolver will timeout later and call Connector::OnDNSResolved with an empty addrs. That will crash.

Test Code:

TEST_UNIT(testTCPClientConnectionTimeout) {
    std::shared_ptr<evpp::EventLoop> loop(new evpp::EventLoop);
    std::shared_ptr<evpp::TCPClient> client(new evpp::TCPClient(loop.get(), "cmake.org:80", "TCPPingPongClient"));
    client->SetConnectionCallback([loop, client](const evpp::TCPConnPtr& conn) {
        loop->Stop();
    });
    client->set_auto_reconnect(false);
    client->set_connecting_timeout(evpp::Duration(0.0001));
    client->Connect();
    loop->Run();
    client.reset();
    loop.reset();
    H_TEST_ASSERT(evpp::GetActiveEventCount() == 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant