drogonframework / drogon

Drogon: A C++14/17/20 based HTTP web application framework running on Linux/macOS/Unix/Windows
MIT License
11.44k stars 1.1k forks source link

drogon find crashed? #2075

Open bethebest0622 opened 3 months ago

bethebest0622 commented 3 months ago

你好,我调用drogon的时候崩溃,崩溃的堆栈信息是:

(gdb) where
#0  0x00007ff6c2fc87ce in Json::Value::find(char const*, char const*) const () from /usr/local/lib/libjsoncpp.so.25
#1  0x00007ff6c2fc9a33 in Json::Value::operator[](char const*) const () from /usr/local/lib/libjsoncpp.so.25
#2  0x00007ff6c2fbd6db in Json::CharReaderBuilder::newCharReader() const () from /usr/local/lib/libjsoncpp.so.25
#3  0x00007ff6c332f83d in drogon::HttpResponseImpl::parseJson() const () from /usr/local/lib/libcurl_util.so
#4  0x00007ff6c3303576 in drogon::HttpClientImpl::handleResponse(std::shared_ptr<drogon::HttpResponseImpl> const&, std::pair<std::shared_ptr<drogon::HttpRequest>, std::function<void (drogon::ReqResult, std::shared_ptr<drogon::HttpResponse> const&)> >&&, std::shared_ptr<trantor::TcpConnection> const&) () from /usr/local/lib/libcurl_util.so
#5  0x00007ff6c33038a4 in drogon::HttpClientImpl::onRecvMessage(std::shared_ptr<trantor::TcpConnection> const&, trantor::MsgBuffer*) () from /usr/local/lib/libcurl_util.so
#6  0x00007ff6c3303c08 in std::_Function_handler<void (std::shared_ptr<trantor::TcpConnection> const&, trantor::MsgBuffer*), drogon::HttpClientImpl::createTcpClient()::{lambda(std::shared_ptr<trantor::TcpConnection> const&, trantor::MsgBuffer*)#1}>::_M_invoke(std::_Any_data const&, std::shared_ptr<trantor::TcpConnection> const&, trantor::MsgBuffer*&&) () from /usr/local/lib/libcurl_util.so
#7  0x00007ff6c33d8f64 in trantor::TcpConnectionImpl::onSslMessage(trantor::TcpConnection*, trantor::MsgBuffer*) () from /usr/local/lib/libcurl_util.so
#8  0x00007ff6c33e88cc in OpenSSLProvider::processApplicationData() () from /usr/local/lib/libcurl_util.so
#9  0x00007ff6c33ed383 in OpenSSLProvider::recvData(trantor::MsgBuffer*) () from /usr/local/lib/libcurl_util.so
#10 0x00007ff6c33dd545 in trantor::TcpConnectionImpl::readCallback() () from /usr/local/lib/libcurl_util.so
#11 0x00007ff6c33d1228 in trantor::Channel::handleEventSafely() () from /usr/local/lib/libcurl_util.so
#12 0x00007ff6c33d12c1 in trantor::Channel::handleEvent() () from /usr/local/lib/libcurl_util.so
#13 0x00007ff6c33c0f4c in trantor::EventLoop::loop() () from /usr/local/lib/libcurl_util.so
#14 0x00007ff6c33c1eb0 in trantor::EventLoopThread::loopFuncs() () from /usr/local/lib/libcurl_util.so
#15 0x00007ff6c28f8b23 in execute_native_thread_routine () from /lib64/libstdc++.so.6
#16 0x00007ff6c2d911ca in start_thread () from /lib64/libpthread.so.0
#17 0x00007ff6c1f10e73 in clone () from /lib64/libc.so.6

请问一下,什么情况下会出现这种错误呢,出现之后有啥处理办法可以不crash,感谢

an-tao commented 3 months ago

崩在jsoncpp库里了,这种通常是由于兼容性问题造成的,比如你使用的jsoncpp的头文件和连接的jsoncpp的so文件版本不匹配。

bethebest0622 commented 3 months ago

崩在jsoncpp库里了,这种通常是由于兼容性问题造成的,比如你使用的jsoncpp的头文件和连接的jsoncpp的so文件版本不匹配。

如果不匹配 应该是100%崩溃吧,但我现在遇到的情况是,只有1%会崩溃,我怀疑是网络状况不好的情况下,httpresponse的json返回异常,这个您有啥建议吗

an-tao commented 3 months ago

看调用堆栈还没到parse那步呢,尝试下升级jsoncpp库

nqf commented 3 months ago

json 嵌套深吗?

void HttpResponseImpl::parseJson() const
{
    static std::once_flag once;
    static Json::CharReaderBuilder builder;
    std::call_once(once, []() {
        builder["collectComments"] = false;
        builder["stackLimit"] =
            static_cast<Json::UInt>(drogon::app().getJsonParserStackLimit());
    });

image

bethebest0622 commented 3 months ago

json 嵌套深吗?

void HttpResponseImpl::parseJson() const
{
    static std::once_flag once;
    static Json::CharReaderBuilder builder;
    std::call_once(once, []() {
        builder["collectComments"] = false;
        builder["stackLimit"] =
            static_cast<Json::UInt>(drogon::app().getJsonParserStackLimit());
    });

image

不深,非常浅,大多数都是正确的,就是偶尔会集中的报这个问题,所以我怀疑是网络状况不好的时候 出现的

bethebest0622 commented 3 months ago

core文件也是 core-EventLoopThread-194672-1718641976 这种

bethebest0622 commented 3 months ago

发生崩溃的时候 似乎是一连串的 如图 image

nqf commented 3 months ago

json 嵌套深吗?

void HttpResponseImpl::parseJson() const
{
    static std::once_flag once;
    static Json::CharReaderBuilder builder;
    std::call_once(once, []() {
        builder["collectComments"] = false;
        builder["stackLimit"] =
            static_cast<Json::UInt>(drogon::app().getJsonParserStackLimit());
    });

image

不深,非常浅,大多数都是正确的,就是偶尔会集中的报这个问题,所以我怀疑是网络状况不好的时候 出现的

想法吧 http body 打出来, 看看json 是不是有问题, 再就是 你升级 json cpp 试试吧, 目前这些信息很难定位出问题

bethebest0622 commented 3 months ago

json 嵌套深吗?

void HttpResponseImpl::parseJson() const
{
    static std::once_flag once;
    static Json::CharReaderBuilder builder;
    std::call_once(once, []() {
        builder["collectComments"] = false;
        builder["stackLimit"] =
            static_cast<Json::UInt>(drogon::app().getJsonParserStackLimit());
    });

image

不深,非常浅,大多数都是正确的,就是偶尔会集中的报这个问题,所以我怀疑是网络状况不好的时候 出现的

想法吧 http body 打出来, 看看json 是不是有问题, 再就是 你升级 json cpp 试试吧, 目前这些信息很难定位出问题

http body 是说没有json解析之前的字节流 打印出来吗? 另外我的jsoncpp是 libjsoncpp.so.1.9.5

nqf commented 3 months ago

stackLimit

对的, bodyPtr_->getString() 这个东西 打出来看看是什么

nqf commented 3 months ago

@an-tao resp->parseJson(); 可以在这添加一个开关来关闭它吗, 每次响应它都会自动解析 json, 这对于不需要使用getJsonObject()的用户似乎是不必要的开销

an-tao commented 3 months ago

@an-tao resp->parseJson(); 可以在这添加一个开关来关闭它吗, 每次响应它都会自动解析 json, 这对于不需要使用getJsonObject()的用户似乎是不必要的开销

可以的,你提PR吧,仿照server端处理request的方式,延迟parse