Title: Exception in async_server_base/async_connection during port scanning (nmap) · Issue #677 · cpp-netlib/cpp-netlib · GitHub
Open Graph Title: Exception in async_server_base/async_connection during port scanning (nmap) · Issue #677 · cpp-netlib/cpp-netlib
X Title: Exception in async_server_base/async_connection during port scanning (nmap) · Issue #677 · cpp-netlib/cpp-netlib
Description: When boost::network::http::server is listening for new connections, it sometimes throws the following exception from it's run() method (or asio::io_service::run()) when the host is being port scanned using nmap: boost::exception_detail::...
Open Graph Description: When boost::network::http::server is listening for new connections, it sometimes throws the following exception from it's run() method (or asio::io_service::run()) when the host is being port scann...
X Description: When boost::network::http::server is listening for new connections, it sometimes throws the following exception from it's run() method (or asio::io_service::run()) when the host is being port s...
Opengraph URL: https://github.com/cpp-netlib/cpp-netlib/issues/677
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Exception in async_server_base/async_connection during port scanning (nmap)","articleBody":"When `boost::network::http::server` is listening for new connections, it sometimes throws the following exception from it's `run()` method (or `asio::io_service::run()`) when the host is being port scanned using nmap:\n\n```\nboost::exception_detail::clone_impl\u003cboost::exception_detail::error_info_injector\u003cstd::system_error\u003e\u003e\nremote_endpoint: Transport endpoint is not connected\n```\n\nAfter the exception servers stops accepting connections even if event loop is restarted and has to be `stop()`'ed and `listen()``ed again. In my tests, depending on the system, this may happen every time the host in nmap'ed or require several consequent nmaps.\n\nThis bug actually has already been reported (issue #360), but for an old version of cpp-netlib and there was no activity, so i decided to open a new issue. I am experiencing this problem with cpp-netlib 0.12.0.\n\nI have fixed the issue in my project with the following patch. I am unsure if i have fixed it the right way (for example, i might have introduced breaking API change in `stream_handler::remote_endpoint()`), but if it is ok, i can send a pull request.\n\n```\ndiff --git a/boost/network/protocol/http/server/async_connection.hpp b/boost/network/protocol/http/server/async_connection.hpp\nindex 915c6fb..eca2f68 100644\n--- a/boost/network/protocol/http/server/async_connection.hpp\n+++ b/boost/network/protocol/http/server/async_connection.hpp\n@@ -462,11 +462,18 @@ struct async_connection\n enum state_t { method, uri, version, headers };\n\n void start() {\n- typename ostringstream\u003cTag\u003e::type ip_stream;\n- ip_stream \u003c\u003c socket_.remote_endpoint().address().to_string() \u003c\u003c ':'\n- \u003c\u003c socket_.remote_endpoint().port();\n- request_.source = ip_stream.str();\n- read_more(method);\n+ std::error_code ec;\n+ auto remote_endpoint = socket_.remote_endpoint(ec);\n+ \n+ if (ec) {\n+ error_encountered = in_place\u003cstd::system_error\u003e(ec);\n+ } else {\n+ typename ostringstream\u003cTag\u003e::type ip_stream;\n+ ip_stream \u003c\u003c remote_endpoint.address().to_string() \u003c\u003c ':'\n+ \u003c\u003c remote_endpoint.port();\n+ request_.source = ip_stream.str();\n+ read_more(method);\n+ }\n }\n\n void read_more(state_t state) {\ndiff --git a/boost/network/protocol/stream_handler.hpp b/boost/network/protocol/stream_handler.hpp\nindex 16fafc6..9d82706 100644\n--- a/boost/network/protocol/stream_handler.hpp\n+++ b/boost/network/protocol/stream_handler.hpp\n@@ -109,11 +109,11 @@ struct stream_handler {\n }\n }\n\n- tcp_socket::endpoint_type remote_endpoint() const {\n+ tcp_socket::endpoint_type remote_endpoint(std::error_code\u0026 ec) const {\n if (ssl_enabled) {\n- return ssl_sock_-\u003enext_layer().remote_endpoint();\n+ return ssl_sock_-\u003enext_layer().remote_endpoint(ec);\n } else {\n- return tcp_sock_-\u003eremote_endpoint();\n+ return tcp_sock_-\u003eremote_endpoint(ec);\n }\n }\n\n```\n","author":{"url":"https://github.com/vovams","@type":"Person","name":"vovams"},"datePublished":"2016-08-08T15:07:26.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/677/cpp-netlib/issues/677"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:465058c9-1796-584c-e403-e7a22d65f828 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E9A4:343EA:178A618:1FD3E89:696EAD83 |
| html-safe-nonce | 80860c5987f460513b87f1204e625c8e9389930d563ae07ec5c86e095e61e170 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOUE0OjM0M0VBOjE3OEE2MTg6MUZEM0U4OTo2OTZFQUQ4MyIsInZpc2l0b3JfaWQiOiI4OTg1NTI3NTk3NTk4NDI2OTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 18f1d39315a9998a49c38c03a5218a8d007d8e926611308ebce7dbc88c2bfe46 |
| hovercard-subject-tag | issue:169946271 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/cpp-netlib/cpp-netlib/677/issue_layout |
| twitter:image | https://opengraph.githubassets.com/312490f0d47091c09def01fb920bf50e3f2564e31ad8b9189fac030501a5beb3/cpp-netlib/cpp-netlib/issues/677 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/312490f0d47091c09def01fb920bf50e3f2564e31ad8b9189fac030501a5beb3/cpp-netlib/cpp-netlib/issues/677 |
| og:image:alt | When boost::network::http::server is listening for new connections, it sometimes throws the following exception from it's run() method (or asio::io_service::run()) when the host is being port scann... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | vovams |
| hostname | github.com |
| expected-hostname | github.com |
| None | b278ad162d35332b6de714dfb005de04386c4d92df6475522bef910f491a35ee |
| turbo-cache-control | no-preview |
| go-import | github.com/cpp-netlib/cpp-netlib git https://github.com/cpp-netlib/cpp-netlib.git |
| octolytics-dimension-user_id | 192422 |
| octolytics-dimension-user_login | cpp-netlib |
| octolytics-dimension-repository_id | 494068 |
| octolytics-dimension-repository_nwo | cpp-netlib/cpp-netlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | true |
| octolytics-dimension-repository_parent_id | 469399 |
| octolytics-dimension-repository_parent_nwo | glynos/cpp-netlib |
| octolytics-dimension-repository_network_root_id | 469399 |
| octolytics-dimension-repository_network_root_nwo | glynos/cpp-netlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 39aed5006635ab6f45e6b77d23e73b08a00272a3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width