CPU usage 100% ( Request hangs ) #496

Closed
spritab opened this Issue Feb 11, 2015 · 4 comments

Comments

Projects
None yet
2 participants
@spritab

spritab commented Feb 11, 2015

The http client application hangs in infinite loop in io_service::run, if server accept connection and do nothing. There are no reaction on closing socket at server side.
You can reproduce this using following steps:

  • run server using command at separate terminal:
while true; do echo "" | nc -l 8091; done
  • compile and run the program:
// main.cpp 
#include <iostream>
#include <boost/network/include/http/client.hpp>
int main ( int argc, char *argv[] )
{
  typedef boost::network::http::basic_client<
      boost::network::http::tags::http_async_8bit_tcp_resolve, 1, 1> 
      Client;
  Client client;
  Client::request req("http://localhost:8091");
  Client::response resp = client.get(req);
  std::cout << body(resp) << std::endl;
  return 0;
}

This program will work forever ( ever you terminate netcat ), and you can observe 100% CPU usage by this program at top utility.
system: Ubuntu 14.04 LTS 64bit
boost version: 1.54
cpp-netlib version: 0.11-devel (cpp-netlib-0.11.1-final also consists this isssue)

$ cat /usr/include/boost/version.hpp  | fgrep "#define BOOST_LIB_VERSION"
#define BOOST_LIB_VERSION "1_54"
$ git rev-parse HEAD
6e090b3d0b3c4f3b132432a6763594593cf7f365
$ git branch
* 0.11-devel
$ g++ --version
g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2

Jetty shows such server behaivior, when there are lack of memory.

@spritab

This comment has been minimized.

Show comment
Hide comment
@spritab

spritab Feb 11, 2015

The same behaivior (100% CPU usage). It's possible to get if server responses with incorrect status like:

HTTP/1.0 200
while true; do echo "HTTP/1.0 200" | nc -l 8091; done

spritab commented Feb 11, 2015

The same behaivior (100% CPU usage). It's possible to get if server responses with incorrect status like:

HTTP/1.0 200
while true; do echo "HTTP/1.0 200" | nc -l 8091; done
@spritab

This comment has been minimized.

Show comment
Hide comment
@spritab

spritab Feb 11, 2015

It looks like that there are no cases for boost eof error while parsing http headers at handle_received_data (boost/network/protocol/http/client/connection/async_normal.hpp:252)
If eof happens while app parse headers it calls parse_version/parse_status/parse_status_message/parse_headers which doesn't care about eof error, these functions just call delegate_->read_some and we got loop here, because asio will callback with eof error again.
I fixed this issue, just stop parsing, but I suppose it's just workaround.

spritab commented Feb 11, 2015

It looks like that there are no cases for boost eof error while parsing http headers at handle_received_data (boost/network/protocol/http/client/connection/async_normal.hpp:252)
If eof happens while app parse headers it calls parse_version/parse_status/parse_status_message/parse_headers which doesn't care about eof error, these functions just call delegate_->read_some and we got loop here, because asio will callback with eof error again.
I fixed this issue, just stop parsing, but I suppose it's just workaround.

@deanberris

This comment has been minimized.

Show comment
Hide comment
@deanberris

deanberris Feb 11, 2015

Member

Thanks @spritab -- good catch! The fix would really be to raise an exception if we haven't gotten through the full proper response, but still populate fields that we've already parsed (instead of just stopping the parsing). Do you mind sending a pull request on top of 0.11-devel?

Member

deanberris commented Feb 11, 2015

Thanks @spritab -- good catch! The fix would really be to raise an exception if we haven't gotten through the full proper response, but still populate fields that we've already parsed (instead of just stopping the parsing). Do you mind sending a pull request on top of 0.11-devel?

@spritab

This comment has been minimized.

Show comment
Hide comment
@spritab

spritab Feb 16, 2015

@deanberris, thanks for quick response, and sorry for long response from me.
Unfortinaty, I don't have enought time to prepare pull request in the near future(may be sometimes later).

spritab commented Feb 16, 2015

@deanberris, thanks for quick response, and sorry for long response from me.
Unfortinaty, I don't have enought time to prepare pull request in the near future(may be sometimes later).

@deanberris deanberris self-assigned this Mar 16, 2015

@deanberris deanberris added this to the 0.11.2 milestone Mar 16, 2015

deanberris added a commit that referenced this issue Mar 25, 2015

@deanberris deanberris closed this Sep 11, 2015

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