Skip to content

Commit

Permalink
Merge pull request #1699 from AntelopeIO/GH-1662-close
Browse files Browse the repository at this point in the history
Improve trx_generator http client
  • Loading branch information
heifner authored Oct 3, 2023
2 parents ba88d0a + 4c45ac0 commit f239a63
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 4 additions & 5 deletions tests/trx_generator/http_client_async.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class session : public std::enable_shared_from_this<session> {
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
Expand Down Expand Up @@ -129,16 +132,12 @@ class session : public std::enable_shared_from_this<session> {
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)
Expand Down
4 changes: 4 additions & 0 deletions tests/trx_generator/trx_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ namespace eosio::testing {
[this, trx_id = trx.id()](boost::beast::error_code ec,
boost::beast::http::response<boost::beast::http::string_body> 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 {
Expand Down

0 comments on commit f239a63

Please sign in to comment.