Qihoo360 / evpp

A modern C++ network library for developing high performance network services in TCP/UDP/HTTP protocols.
BSD 3-Clause "New" or "Revised" License
3.61k stars 948 forks source link

evpp 定时查询nsqlookupd 内存泄漏的问题 #266

Closed chenweiwei417 closed 2 years ago

chenweiwei417 commented 3 years ago

client.cc的ConnectToLookupd,这边的r(Request)的handler通过Execute函数持有了自身的引用,在执行完handler()回调后,没有重置handler_,所以r不会被释放,请问这个bug如何修复

    auto f = [this, lookupd_url]() {
        std::shared_ptr<evpp::httpc::Request> r(new evpp::httpc::Request(this->loop_, lookupd_url, "", evpp::Duration(1.0)));
        LOG_ERROR << "query nsqlookupd " << lookupd_url << ";request=" << r << ";real=" << r.get() << ";use_count=" << r.use_count();
        r->Execute(std::bind(&Client::HandleLoopkupdHTTPResponse, this, std::placeholders::_1, r));
        LOG_ERROR << "query nsqlookupd end,use_count=" << r.use_count();
    };

    // query nsqlookupd immediately right now
    loop_->RunInLoop(f);

    // query nsqlookupd periodic
    auto timer = loop_->RunEvery(option_.query_nsqlookupd_interval, f);
   lookupd_timers_.push_back(timer);
}
chenweiwei417 commented 3 years ago

详情见博客:https://blog.csdn.net/cww_zju_amdocs/article/details/114589626,暂时的解决方法是在response.cc的析构函数里面调用request_->conn()->Close();释放evhttp_conn_连接,避免了部分内存泄漏,没有完全解决

jinguoli commented 2 years ago

fixed by pr #291