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

Server returns TWO responses for ONE Request #26

Open
TheQue42 opened this issue Feb 19, 2025 · 1 comment
Open

Server returns TWO responses for ONE Request #26

TheQue42 opened this issue Feb 19, 2025 · 1 comment

Comments

@TheQue42
Copy link

I've tried integrating this repo into my application, just to test oatpp.

First of, if I do it exactly, I will get compilation warnings from gcc14:

include/ecmi/EcmiComponent.hpp:49:62: warning: declaration of ‘executor’ shadows a member of ‘AppComponent’ [-Wshadow]

If I rename the executor in in AppComponent.hpp (My code uses the ecmi prefix), it compiles without warnings, and application will start successfully, and bind to the socket.

BUT. Sending in curl -v -s http://127.0.0.1:7070/hello, will result in TWO responses, when tracing the connection with ngrep, as can be seen below.

I'd like to troubelshoot the callchains, but I havent been able to figure out how I can increase the logging/tracing of the oatpp library?

#####
T 127.0.0.1:45726 -> 127.0.0.1:7070 [AP] #307
GET /hello HTTP/1.1.
Host: 127.0.0.1:7070.
User-Agent: curl/8.12.1.
Accept: */*.
.

##
T 127.0.0.1:7070 -> 127.0.0.1:45726 [AP] #309
HTTP/1.1 200 OK.
Content-Length: 58.
Connection: keep-alive.
Server: oatpp/1.4.0.
Content-Type: application/json.
.
{"code":42,"message":"Hello World","result":"Really Good"}
###
T 127.0.0.1:7070 -> 127.0.0.1:45726 [AP] #312
HTTP/1.1 500 Internal Server Error.
Content-Length: 109.
Connection: close.
Server: oatpp/1.4.0.
.
server=oatpp/1.4.0
code=500
description=Internal Server Error
stacktrace:
- Error processing async request

###
@TheQue42
Copy link
Author

TheQue42 commented Feb 19, 2025

In my latest attempts in trying to understand the code, I have made some changes in how I start the server, so I'll add them here: My main creates an object of class EcmiServer, which looks like this. But regardless of my changes, I always get the same TWO responses.

I also tried creating a server without using the DI-mechanism (using a lot of ::createShared(), but the same results)

// Params not used yet
EcmiServer::EcmiServer(std::string address, std::uint16_t port)
    : listenPort(port),
      listenAddress(address)
{
    NW_TRACE_ENTER(NwTrace::Ecmi, listenPort, listenAddress);
    oatpp::Environment::init();
}

EcmiServer::~EcmiServer()
{
    NW_TRACE_ENTER(NwTrace::Ecmi, listenPort, listenAddress);
    oatpp::Environment::destroy();
}

void EcmiServer::run()
{
    NW_TRACE_ENTER(NwTrace::Ecmi, listenPort, listenAddress);

    // Not used right now...
    const oatpp::network::Address bindSocket = {listenAddress, listenPort, oatpp::network::Address::IP_4};

    AppComponent components;

    /* Get router component */
    OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router);

    /* Create MyController and add all of its endpoints to router */
    router->addController(std::make_shared<MyController>());

    /* Get connection handler component */
    OATPP_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>, connectionHandler);

    /* Get connection provider component */
    OATPP_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, connectionProvider);

    m_server = oatpp::network::Server::createShared(connectionProvider, connectionHandler);
    std::string lPort = connectionProvider->getProperty("port").toString();
    /* Priny info about server port */
    OATPP_LOGi("MyApp", "Server running on port {}", connectionProvider->getProperty("port").toString())

    /* Run server */
    std::jthread oatThread(&EcmiServer::startServer, this);
    oatThread.detach();
    NW_TRACE_NOTICE(NwTrace::Ecmi, "Running", lPort);
}


void EcmiServer::startServer()
{
    m_server->run();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant