Skip to content

HTTP/fetch query can block event loop (tested on Linux) #31

@lsergiy

Description

@lsergiy

I have http server and http client. Both standard and very minimalist based on examples kindly provided with Nodepp.
I noticed http server may read accepted socked forever blocked. Client side is performing http fetch. Everything is Nodepp based code.

    virtual int __read( char* bf, const ulong& sx ) const noexcept {
        if( process::millis() > get_recv_timeout() || is_closed() )
          { return -1; } if ( sx==0 ) { return 0; }

        SOCKADDR_ST& addr = get_addr(); socklen_t len = sizeof(addr);

        int res = SOCK != SOCK_DGRAM // <<< <<< <<< WE STUCK HERE <<< <<< <<< SOCK is 1 <<< <<< <<<
                ? ::recv    ( obj->fd, bf, sx, 0 )
                : ::recvfrom( obj->fd, bf, sx, 0, (SOCKADDR*) &addr, &len );

Everything runs in separated and dedicated worker thread. Call stack is:

1  __libc_recv                                                                                                                                                                                                                                                                                                                                                                                                                                  recv.c           28  0x7ffff792bc4a 
2  __libc_recv                                                                                                                                                                                                                                                                                                                                                                                                                                  recv.c           23  0x7ffff792bc4a 
3  nodepp::socket_t::__read                                                                                                                                                                                                                                                                                                                                                                                                                     socket.h         629 0x5555556f7f8d 
4  nodepp::socket_t::_read                                                                                                                                                                                                                                                                                                                                                                                                                      socket.h         617 0x5555556f7e75 
5  nodepp::generator::file::read::operator()<nodepp::http_t>                                                                                                                                                                                                                                                                                                                                                                                    generator.h      35  0x55555571c134 
6  nodepp::generator::file::line::operator()<nodepp::http_t>                                                                                                                                                                                                                                                                                                                                                                                    generator.h      117 0x55555570a4e9 
7  nodepp::http_t::read_header                                                                                                                                                                                                                                                                                                                                                                                                                  http.h           160 0x5555556fb284 
8  nodepp::http::fetch(nodepp::fetch_t const&, nodepp::agent_t *, nodepp::function_t<void, nodepp::http_t>)::{lambda(nodepp::function_t<void, nodepp::http_t>, nodepp::function_t<void, nodepp::except_t>)#1}::operator()(nodepp::function_t<void, nodepp::http_t>, nodepp::function_t<void, nodepp::except_t>) const::{lambda(nodepp::http_t)#1}::operator()(nodepp::http_t) const                                                             http.h           244 0x5555556fc81e 
9  nodepp::function_t<void, nodepp::socket_t>::func_impl<nodepp::http::fetch(nodepp::fetch_t const&, nodepp::agent_t *, nodepp::function_t<void, nodepp::http_t>)::{lambda(nodepp::function_t<void, nodepp::http_t>, nodepp::function_t<void, nodepp::except_t>)#1}::operator()(nodepp::function_t<void, nodepp::http_t>, nodepp::function_t<void, nodepp::except_t>) const::{lambda(nodepp::http_t)#1}>::invoke(nodepp::socket_t const&) const function.h       59  0x5555557667cc 
10 nodepp::function_t<void, nodepp::socket_t>::emit                                                                                                                                                                                                                                                                                                                                                                                             function.h       44  0x55555571a5c9 
11 nodepp::function_t<void, nodepp::socket_t>::operator()                                                                                                                                                                                                                                                                                                                                                                                       function.h       40  0x555555709789 
12 nodepp::tcp_t::connect(nodepp::dns_t const&, int, nodepp::function_t<void, nodepp::socket_t>) const::{lambda()#1}::operator()() const                                                                                                                                                                                                                                                                                                        tcp.h            150 0x5555556fa1a1 
13 nodepp::loop_t::add<nodepp::tcp_t::connect(nodepp::dns_t const&, int, nodepp::function_t<void, nodepp::socket_t>) const::{lambda()#1}>(nodepp::tcp_t::connect(nodepp::dns_t const&, int, nodepp::function_t<void, nodepp::socket_t>) const::{lambda()#1}) const::{lambda()#1}::operator()() const                                                                                                                                            loop.h           171 0x55555572bd1e 
14 nodepp::function_t<int>::func_impl<nodepp::loop_t::add<nodepp::tcp_t::connect(nodepp::dns_t const&, int, nodepp::function_t<void, nodepp::socket_t>) const::{lambda()#1}>(nodepp::tcp_t::connect(nodepp::dns_t const&, int, nodepp::function_t<void, nodepp::socket_t>) const::{lambda()#1}) const::{lambda()#1}>::invoke() const                                                                                                            function.h       59  0x555555764b8a 
15 nodepp::function_t<int>::emit                                                                                                                                                                                                                                                                                                                                                                                                                function.h       44  0x555555713b15 
16 nodepp::function_t<int>::operator()                                                                                                                                                                                                                                                                                                                                                                                                          function.h       40  0x5555557036e8 
17 nodepp::loop_t::normal_queue_next() const::{lambda()#1}::operator()() const                                                                                                                                                                                                                                                                                                                                                                  loop.h           82  0x5555556ec78c 
18 nodepp::loop_t::normal_queue_next                                                                                                                                                                                                                                                                                                                                                                                                            loop.h           116 0x5555556ecbaa 
19 nodepp::loop_t::next                                                                                                                                                                                                                                                                                                                                                                                                                         loop.h           156 0x5555556ecd5e 
20 nodepp::kernel_t::next                                                                                                                                                                                                                                                                                                                                                                                                                       kernel.h         277 0x5555556f1c34 
21 nodepp::process::next                                                                                                                                                                                                                                                                                                                                                                                                                        nodepp.h         67  0x5555556f22f7 
22 nodepp::process::wait                                                                                                                                                                                                                                                                                                                                                                                                                        nodepp.h         112 0x5555556f251a 
23 operator()                                                                                                                                                                                                                                                                                                                                                                                                                                   aqt.cpp          79  0x5555557c9746 
24 operator()                                                                                                                                                                                                                                                                                                                                                                                                                                   worker.h         57  0x5555557c9d14 
25 nodepp::function_t<int>::func_impl<nodepp::worker_t::worker_t<bee::net::async_queue_thread::start()::<lambda()>>(bee::net::async_queue_thread::start()::<lambda()>)::<lambda()>>::invoke(void) const                                                                                                                                                                                                                                         function.h       59  0x5555557cbef6 
26 nodepp::function_t<int>::emit                                                                                                                                                                                                                                                                                                                                                                                                                function.h       44  0x555555713b15 
27 nodepp::function_t<int>::operator()                                                                                                                                                                                                                                                                                                                                                                                                          function.h       40  0x5555557036e8 
28 nodepp::worker_t::callback                                                                                                                                                                                                                                                                                                                                                                                                                   worker.h         44  0x5555556f29f9 
29 start_thread                                                                                                                                                                                                                                                                                                                                                                                                                                 pthread_create.c 447 0x7ffff789caa4 
30 clone3                                                                                                                                                                                                                                                                                                                                                                                                                                       clone3.S         78  0x7ffff7929c6c

The key thing to reproduce this issue is same as I described in previous issue: start timer or repeated function call in same thread/event-loop where http server is started.
So, this issue is Linux version of MacOSX issue. I cannot do Windows checks for you, unfortunately. But I think issue should be checked there also because I suspect presence of some logical issue in source code of event loop.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions