eidheim / Simple-Web-Server

A very simple, fast, multithreaded, platform independent HTTP and HTTPS server and client library implemented using C++11 and Boost.Asio. Created to be an easy way to make REST resources available from C++ applications.
MIT License
2.61k stars 751 forks source link

"accept: Already open" error when using HTTP-Client within cucumber test framework #219

Closed pp23 closed 6 years ago

pp23 commented 6 years ago

I have the following initial test cases implemented which will be executed by cucumber-cpp:

GIVEN("^a REST\\-Service is available$") {

   BOOST_TEST(true);
}

WHEN("^I make a HTTP\\-GET\\-Request to the REST\\-Service$") {

// following line leads to "accept: Already open"
   SimpleWeb::Client<SimpleWeb::HTTP> client(host + ':' + std::to_string(port));

   BOOST_TEST(true);
}

THEN("^I want to receive a (\\d+) response with data\\.$") {
  pending(); // Write code here that turns the phrase above into concrete actions
}

When I run the tests cucumber immediately looses the connection because the server (code above) stops its execution with the following print out: accept: Already open I have read here https://stackoverflow.com/questions/10728802/how-to-get-rid-of-accept-already-open-exception-in-boostasio-server that this comes from boost::asio-sockets. But I don't understand why it comes up already on initialization of the client although it only initializes host and port members. Can you imagine where and why boost::asio prints out the error? I could bet that boost::asio gets struggled with the boost::asio::socket which cucumber-cpp uses to open the server.

eidheim commented 6 years ago

Is the server you are running Simple-Web-Server? I see only client code above by the way:) Also, in case it is related, which OS are you on?

pp23 commented 6 years ago

The server is a Simple-Web-Server and the code runs on a linux machine. The issue also comes up when no server gets started. The code above is really enough to get the bug reproduced. Maybe the ioservice has some conflict with the ioservice of the cucumber-server. But I think the problem was within boost because with an update of boost from 1.64 to 1.66 the issue does not occur anymore.