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

codedown #1207

Closed
wangchuanfang opened this issue Feb 25, 2022 · 4 comments
Closed

codedown #1207

wangchuanfang opened this issue Feb 25, 2022 · 4 comments

Comments

@wangchuanfang
Copy link

wangchuanfang commented Feb 25, 2022

Hi yhirose

I use httplib in the following way and it crashes when I do a bake

int CHttpClient::doHttpPost(const std::string host, const std::string path, const std::string body, std::string &response)
{
    int retry_times = RETRY_TIMES; 
    auto port = 80;
    httplib::Client client(host.c_str(), port);  
    client.set_keep_alive(true);
    client.set_connection_timeout(HTTP_CONNECT_TIMEOUT);  
    client.set_read_timeout(HTTP_REQUEST_TIMEOUT);
    client.set_write_timeout(HTTP_REQUEST_TIMEOUT);

    LOG_INFO("[CHttpClient %s] do http post request from host: %s, path: %s, body: %s",  
        __FUNCTION__, host.c_str(), path.c_str(), body.c_str());

    httplib::Headers headers = {
        { "Accept", "*/*" },
        { "Content-Type", "application/json" }    
    };

__retry:    
    auto res = client.Post(path.c_str(), headers, body, "application/json");
    if (res) {
        if(res->status != 200){
            LOG_ERROR("[CHttpClient %s] http post request error return status=[%d], body=[%s]",  
            __FUNCTION__, res->status,  res->body.c_str());
            return -1;
        }else{
            LOG_INFO("[CHttpClient %s] http post request return status=[%d], body=[%s]",  
            __FUNCTION__, res->status,  res->body.c_str());        
        }
        response = res->body;     
    } else {
        if (retry_times > 0) {
            retry_times --;
            LOG_DEBUG("[CHttpClient %s] retry http post, retry times: %d",  __FUNCTION__, retry_times); 
            usleep(HTTP_REQUEST_INTERVAL);       
            goto __retry;
        } else {
            LOG_ERROR("[CHttpClient %s] http post error!!!",  __FUNCTION__);
            return -1;
        }
    } 

    return 0; 
}

The stack information is as follows:

(gdb) bt
#0 __libc_do_syscall () at ../sysdeps/unix/sysv/linux/arm/libc-do-syscall.S:47
#1 0xf744d296 in __libc_signal_restore_set (set=0xf415c7d8) at ../sysdeps/unix/sysv/linux/internal-signals.h:84
#2 __GI_raise ([sig=sig@entry](mailto:sig=sig@entry)=6) at ../sysdeps/unix/sysv/linux/raise.c:48
#3 0xf743e362 in __GI_abort () at abort.c:79
#4 0xf7474b78 in __libc_message ([action=action@entry](mailto:action=action@entry)=(do_abort | do_backtrace), fmt=<optimized out>) at ../sysdeps/posix/libc_fatal.c:181
#5 0xf7474ba6 in __GI___libc_fatal (message=0xf415ca78 "Unexpected error 9 on netlink descriptor 12.\n") at ../sysdeps/posix/libc_fatal.c:191
#6 0xf74d190a in __GI___netlink_assert_response (fd=-199898504, [fd@entry](mailto:fd@entry)=12, result=<optimized out>) at ../sysdeps/unix/sysv/linux/netlink_assert_response.c:102
#7 0xf74d13e2 in make_request (pid=0, fd=12) at ../sysdeps/unix/sysv/linux/check_pf.c:171
#8 __check_pf (seen_ipv4=0x0, [seen_ipv4@entry](mailto:seen_ipv4@entry)=0x65746176, seen_ipv6=0x90, [seen_ipv6@entry](mailto:seen_ipv6@entry)=0xf415dd1f, in6ai=0x14, [in6ai@entry](mailto:in6ai@entry)=0x61730076, in6ailen=0x1,
    [in6ailen@entry](mailto:in6ailen@entry)=0x73616173) at ../sysdeps/unix/sysv/linux/check_pf.c:329
#9 0xf74b001a in __GI_getaddrinfo (name=<optimized out>, service=<optimized out>, hints=<optimized out>, pai=0x0) at ../sysdeps/posix/getaddrinfo.c:2308
#10 0x000fc2a6 in int httplib::detail::create_socket<httplib::detail::create_client_socket(char const*, int, bool, std::function<void (int)>, long, long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, httplib::Error&)::{lambda(int, addrinfo&)#1}>(char const*, int, int, bool, std::function<void (int)>, httplib::detail::create_client_socket(char const*, int, bool, std::function<void (int)>, long, long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, httplib::Error&)::{lambda(int, addrinfo&)#1}) ()
#11 0x000f4ce8 in httplib::detail::create_client_socket(char const*, int, bool, std::function<void (int)>, long, long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, httplib::Error&) ()
#12 0x000f7c02 in httplib::ClientImpl::create_client_socket(httplib::Error&) const ()
#13 0x000f7c4c in httplib::ClientImpl::create_and_connect_socket(httplib::ClientImpl::Socket&, httplib::Error&) ()
#14 0x000f8236 in httplib::ClientImpl::send(httplib::Request const&, httplib::Response&, httplib::Error&) ()
#15 0x000f9a7e in httplib::ClientImpl::send_with_content_provider(char const*, char const*, std::multimap<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, httplib::detail::ci, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, std::function<bool (unsigned int, unsigned int, httplib::DataSink&)>, std::function<bool (unsigned int, httplib::DataSink&)>, char const*, httplib::Error&) ()
#16 0x000f9b6a in httplib::ClientImpl::send_with_content_provider(char const*, char const*, std::multimap<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, httplib::detail::ci, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, std::function<bool (unsigned int, unsigned int, httplib::DataSink&)>, std::function<bool (unsigned int, httplib::DataSink&)>, char const*) ()
#17 0x000fa2c6 in httplib::ClientImpl::Post(char const*, std::multimap<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, httplib::detail::ci, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*) ()

The error message is as follows:

[19 21:35:08 014]  Unexpected error 9 on netlink descriptor 12.
@PixlRainbow
Copy link
Contributor

Based on Google search, "error 9 on netlink descriptor 12" may happen if a thread closes its socket handle a second time after the system has already allocated the handle ID to a different thread's socket open call.
@yhirose this suggest that somewhere in httplib client there is a socket close call being called redundantly

@yhirose
Copy link
Owner

yhirose commented Feb 27, 2022

@wangchuanfang, could you create the smallest possible code example to reproduce this problem? Then, I'll try to reproduce it on my machine for debugging. Thanks!

@yhirose
Copy link
Owner

yhirose commented Mar 5, 2022

@yhirose this suggest that somewhere in httplib client there is a socket close call being called redundantly

I probably don't understand your comment fully though, It seems that it's an application responsibility. httplib::Client::send itself is a single thread call. So if the problem is caused by such a multithread condition, threads are created on a higher level and there is no way for httplib to figure out such redundant file descriptors. At least what httplib can is to expose a socket descriptor, so that the application can check if the socket is already close.

curl/curl#3386
https://stackoverflow.com/questions/58827641/getaddrinfo-calls-assert-in-the-program

@yhirose
Copy link
Owner

yhirose commented Mar 5, 2022

@wangchuanfang, for now, I'll close it.

@yhirose yhirose closed this as completed Mar 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants