diff --git a/plugins/http_plugin/include/eosio/http_plugin/beast_http_session.hpp b/plugins/http_plugin/include/eosio/http_plugin/beast_http_session.hpp index 6496d51ac5..4ad2d928f0 100644 --- a/plugins/http_plugin/include/eosio/http_plugin/beast_http_session.hpp +++ b/plugins/http_plugin/include/eosio/http_plugin/beast_http_session.hpp @@ -503,7 +503,8 @@ class beast_http_session : public detail::abstract_conn, try { // Send a shutdown signal beast::error_code ec; - socket_.shutdown(Socket::shutdown_send, ec); + socket_.shutdown(Socket::shutdown_both, ec); + socket_.close(ec); // At this point the connection is closed gracefully } catch(...) { handle_exception(); diff --git a/tests/trx_generator/http_client_async.hpp b/tests/trx_generator/http_client_async.hpp index d55dff5e46..7aad239e5c 100644 --- a/tests/trx_generator/http_client_async.hpp +++ b/tests/trx_generator/http_client_async.hpp @@ -74,6 +74,9 @@ class session : public std::enable_shared_from_this { req_.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING); req_.set(http::field::content_type, content_type); req_.body() = std::move(request_body); + // current implementation does not reuse socket, disable keep_alive + req_.set(http::field::connection, "close"); + req_.keep_alive(false); req_.prepare_payload(); // Look up the domain name @@ -129,16 +132,12 @@ class session : public std::enable_shared_from_this { void on_read(beast::error_code ec, std::size_t bytes_transferred) { boost::ignore_unused(bytes_transferred); - if (ec) { - response_callback_(ec, {}); - return fail(ec, "read"); - } - // Write the response message to the callback response_callback_(ec, res_); // Gracefully close the socket stream_.socket().shutdown(tcp::socket::shutdown_both, ec); + stream_.close(); // not_connected happens sometimes so don't bother reporting it. if (ec && ec != beast::errc::not_connected) diff --git a/tests/trx_generator/trx_provider.cpp b/tests/trx_generator/trx_provider.cpp index df2541146e..190c6b4632 100644 --- a/tests/trx_generator/trx_provider.cpp +++ b/tests/trx_generator/trx_provider.cpp @@ -133,6 +133,10 @@ namespace eosio::testing { [this, trx_id = trx.id()](boost::beast::error_code ec, boost::beast::http::response response) { trx_acknowledged(trx_id, fc::time_point::now()); + if (ec) { + elog("http error: ${c}: ${m}", ("c", ec.value())("m", ec.message())); + throw std::runtime_error(ec.message()); + } if (this->needs_response_trace_info() && response.result() == boost::beast::http::status::ok) { try {