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

[Win10][1.7.3] Poco::Net::NoMessageException raised few seconds after HTTP/GET #1293

Closed
alexgille opened this Issue Jun 7, 2016 · 5 comments

Comments

Projects
None yet
3 participants
@alexgille

alexgille commented Jun 7, 2016

Hi,

I'm building a simple web server using Poco with Visual Studio 2015 on Windows 10.

A Poco::Net::NoMessageException is raised few seconds (approx. 15 secs) after connecting to this server with a web browser. It will happen again after refreshing the page; its doing this after each connection.

I didn't find anything in documentation, forum, stackoverflow. It would be very helpful to have a description in documentation of how/when/why these exceptions coming from deep inside the library are raised.

I also tried a std::cout << req.getURI() << std::endl; in handleRequest(...) and got a Memory Access Violation at address 0x00000000 with no other code in function.

MyApp.c

int main(int argc, char ** argv)
{
    myHTTPServer server;
    return server.run(argc, argv);
}

myHTTPRequestHandlerFactory

// Header
class myHTTPRequestHandlerFactory : public HTTPRequestHandlerFactory
{
    public:
        virtual HTTPRequestHandler* createRequestHandler(const HTTPServerRequest&);
};

// Code
HTTPRequestHandler* myHTTPRequestHandlerFactory::createRequestHandler(const HTTPServerRequest& handler) {
    return new myHTTPRequestHandler;
}

myHTTPRequestHandler

// Header
class myHTTPRequestHandler : public HTTPRequestHandler
{
    public:
        virtual void handleRequest(HTTPServerRequest &, HTTPServerResponse &);
};

// Code
void myHTTPRequestHandler::handleRequest(HTTPServerRequest & request, HTTPServerResponse & response) {
    response.setStatus(HTTPResponse::HTTP_OK);
    //response.setContentLength(1024);
    //response.setChunkedTransferEncoding(true);
    std::ostream& out = response.send();
    out << "<html><head></head><body>POCO POCO POCO</body></html>";
    out.flush();
}

myHTTPServer

// Header
class myHTTPServer : public ServerApplication
{
    protected:
        int main(const std::vector<std::string>& v) {
            HTTPServer server(new myHTTPRequestHandlerFactory, ServerSocket(80), new HTTPServerParams);

            server.start();

            std::cout << "Server started" << std::endl;

            waitForTerminationRequest();

            std::cout << "Server stopped" << std::endl;

            server.stop();

            return Application::EXIT_OK;
        }
};

// No code in .c file

Thanks for helping me out

@micheleselea

This comment has been minimized.

Show comment
Hide comment
@micheleselea

micheleselea Jun 16, 2016

Contributor

do you see the port 80 open in your system?
if you do "telnet localhost 80" are you connecting to the port?
do you reach the line "std::ostream& out = response.send();"?
You can even use .sendBuffer(sReply.data(),sReply.length())

Contributor

micheleselea commented Jun 16, 2016

do you see the port 80 open in your system?
if you do "telnet localhost 80" are you connecting to the port?
do you reach the line "std::ostream& out = response.send();"?
You can even use .sendBuffer(sReply.data(),sReply.length())

@micheleselea

This comment has been minimized.

Show comment
Hide comment
@micheleselea

micheleselea Jun 16, 2016

Contributor

have you try to start from HTTPTimeserver from poco samples?

Contributor

micheleselea commented Jun 16, 2016

have you try to start from HTTPTimeserver from poco samples?

@alexgille

This comment has been minimized.

Show comment
Hide comment
@alexgille

alexgille Jun 17, 2016

Port 80 is free, code is executing fine (except for this NoMessageException) and Poco examples have the same issue

alexgille commented Jun 17, 2016

Port 80 is free, code is executing fine (except for this NoMessageException) and Poco examples have the same issue

@obiltschnig

This comment has been minimized.

Show comment
Hide comment
@obiltschnig

obiltschnig Jun 17, 2016

Member

Normally this exception can be safely ignored. It happens when the web server tries to read the next HTTP request header from the socket, but does not receive one because the connection is closed by the client. The reason for this is keep-alive handling: Browser and server keep the connection open after a request in case further requests will be sent, to avoid having to create a new socket connection for each request. However, there's no way to orderly close a keep alive connection after a timeout, other than simply closing the connection, which usually leads to this exception. The exception is handled (ignored) internally and should not leak to the outside.
You can turn off persistent connections by passing a Poco::Net::HTTPServerParams objects configured with setKeepAlive(false) to the HTTPServer instance.

Member

obiltschnig commented Jun 17, 2016

Normally this exception can be safely ignored. It happens when the web server tries to read the next HTTP request header from the socket, but does not receive one because the connection is closed by the client. The reason for this is keep-alive handling: Browser and server keep the connection open after a request in case further requests will be sent, to avoid having to create a new socket connection for each request. However, there's no way to orderly close a keep alive connection after a timeout, other than simply closing the connection, which usually leads to this exception. The exception is handled (ignored) internally and should not leak to the outside.
You can turn off persistent connections by passing a Poco::Net::HTTPServerParams objects configured with setKeepAlive(false) to the HTTPServer instance.

@alexgille

This comment has been minimized.

Show comment
Hide comment
@alexgille

alexgille Jul 11, 2016

Hi,
first, sorry for the late answer, i'm running short of time.
To me, raising an exception at runtime while nothing went wrong and there's no error to handle is a confusing behaviour, as the developper would expect exceptions to be raised only when a malfunction occured at some point.
It's more confusing while the POCO documentation for Web Socket related classes does not refer to this exception as a normal behaviour.
I understand that it's technically relevant to raise this exception at connection level, but it can be misunderstood at server level at runtime.

alexgille commented Jul 11, 2016

Hi,
first, sorry for the late answer, i'm running short of time.
To me, raising an exception at runtime while nothing went wrong and there's no error to handle is a confusing behaviour, as the developper would expect exceptions to be raised only when a malfunction occured at some point.
It's more confusing while the POCO documentation for Web Socket related classes does not refer to this exception as a normal behaviour.
I understand that it's technically relevant to raise this exception at connection level, but it can be misunderstood at server level at runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment