Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #9412 from EOSIO/port_flight_bytes_fix_into_releas…
Browse files Browse the repository at this point in the history
…e/2.0.x

port the fix of flight bytes bug into release/2.0.x
  • Loading branch information
vzqzhang authored Aug 19, 2020
2 parents 91e57cb + 159fdda commit 8da6a23
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions plugins/http_plugin/http_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ namespace eosio {
con->send_http_response();
return false;
}

return true;
}

Expand Down Expand Up @@ -393,7 +394,7 @@ namespace eosio {
:object(std::move(object))
,impl(impl)
{
count = detail::in_flight_sizeof(object);
count = detail::in_flight_sizeof(this->object);
impl.bytes_in_flight += count;
}

Expand Down Expand Up @@ -448,7 +449,7 @@ namespace eosio {
*/
template<typename T>
static auto make_in_flight(T&& object, http_plugin_impl& impl) {
return in_flight<T>(std::forward<T>(object), impl);
return std::make_shared<in_flight<T>>(in_flight<T>(std::forward<T>(object), impl));
}

/**
Expand All @@ -463,17 +464,22 @@ namespace eosio {
detail::internal_url_handler make_app_thread_url_handler( int priority, url_handler next ) {
auto next_ptr = std::make_shared<url_handler>(std::move(next));
return [this, priority, next_ptr=std::move(next_ptr)]( detail::abstract_conn_ptr conn, string r, string b, url_response_callback then ) mutable {
auto tracked_b = make_in_flight(std::move(b), *this);
auto tracked_b = make_in_flight<string>(std::move(b), *this);
if (!conn->verify_max_bytes_in_flight()) {
return;
}

url_response_callback wrapped_then = [tracked_b, then=std::move(then)](int code, fc::variant resp)
{
then(code, std::move(resp));
};

// post to the app thread taking shared ownership of next (via std::shared_ptr),
// sole ownership of the tracked body and the passed in parameters
app().post( priority, [next_ptr, conn=std::move(conn), r=std::move(r), tracked_b=std::move(tracked_b), then=std::move(then)]() mutable {
app().post( priority, [next_ptr, conn=std::move(conn), r=std::move(r), tracked_b, wrapped_then=std::move(wrapped_then)]() mutable {
try {
// call the `next` url_handler and wrap the response handler
(*next_ptr)( std::move( r ), std::move( *tracked_b ), std::move(then)) ;
(*next_ptr)( std::move( r ), std::move(*(*tracked_b)), std::move(wrapped_then)) ;
} catch( ... ) {
conn->handle_exception();
}
Expand Down Expand Up @@ -516,9 +522,9 @@ namespace eosio {
// post back to an HTTP thread to to allow the response handler to be called from any thread
boost::asio::post( thread_pool->get_executor(), [this, con, code, tracked_response=std::move(tracked_response)]() {
try {
std::string json = fc::json::to_string( *tracked_response, fc::time_point::now() + max_response_time );
std::string json = fc::json::to_string( *(*tracked_response), fc::time_point::now() + max_response_time );
auto tracked_json = make_in_flight(std::move(json), *this);
con->set_body( std::move( *tracked_json ) );
con->set_body( std::move( *(*tracked_json) ) );
con->set_status( websocketpp::http::status_code::value( code ) );
con->send_http_response();
} catch( ... ) {
Expand Down

0 comments on commit 8da6a23

Please sign in to comment.