Skip to content

Commit

Permalink
Set keep_alive false and indicate close on reply.
Browse files Browse the repository at this point in the history
Also add better error handling for ec
  • Loading branch information
heifner committed Sep 29, 2023
1 parent 5de8cf5 commit 25bb157
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 3 additions & 5 deletions tests/trx_generator/http_client_async.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ class session : public std::enable_shared_from_this<session> {
req_.set(http::field::host, host);
req_.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING);
req_.set(http::field::content_type, content_type);
req_.set(http::field::connection, "close");
req_.body() = std::move(request_body);
req_.keep_alive(false);
req_.prepare_payload();

// Look up the domain name
Expand Down Expand Up @@ -129,16 +131,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 25bb157

Please sign in to comment.