1

I am trying to write a server which calls another server, then, waits for its response and then sends back it's the response. So I have created a single libnghttp2_asio client session and using this to send requests to the other server in the handler function. It works for a few requests. Unfortunately, whenever I do a load test for the first server, I am getting an error server: asio_client_session_impl.cc:611: void nghttp2::asio_http2::client::session_impl::enter_callback(): Assertion !inside_callback_ failed. after some requests ..

How do I resolve it?

int main(int argc, char *argv[]) {
        boost::system::error_code ec;
        boost::asio::ssl::context tls(boost::asio::ssl::context::sslv23);       
    tls.use_private_key_file("localhost-privkey.pem", boost::asio::ssl::context::pem);
        tls.use_certificate_chain_file("localhost-cert.pem");
        configure_tls_context_easy(ec, tls);
        boost::system::error_code ec2;
        boost::asio::io_service io_service;
        // second server address
        session sess(io_service,"second_server_address ", "3000");
        sess.on_connect([](tcp::resolver::iterator endpoint_it) {

          // get the thread id for printing
          std::thread::id this_id = std::this_thread::get_id();
          std:cerr << "Session connected    tID :    "<< this_id  << std::endl;

        });

        sess.on_error([](const boost::system::error_code &ec) {
                        std::cerr << "C:error: " << ec.message() << std::endl;
        });


        // http2 server
        http2 server;

        // pass the number of threads
        server.num_threads(1);

        server.handle("/test",[&sess, &ec2 ](const nghttp2::asio_http2::server::request &req, const nghttp2::asio_http2::server::response &res)        {
                        auto req2 = sess.submit(ec2, "POST","http://second_server_address:3000/test");
                        req2->on_response([&res](const nghttp2::asio_http2::client::response &res2) {
                            std::cerr << "response was received" << std::endl;
                                           res.write_head(200);
                                           res.end("random data");


                        });

                        req2->on_close([](uint32_t error_code) {
                           std::cerr << "request done closed" << error_code << std::endl;
                        });


        });

        if (server.listen_and_serve(ec,tls, "0.0.0.0", "3000",true)) {
                std::cerr << "S:error " << ec.message() << std::endl;
        }

        io_service.run();

}
UchihaItachi
  • 2,602
  • 14
  • 21

0 Answers0