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

Avoid possibly lengthy destruction of wasm instances on shutdown #7177

Merged
merged 3 commits into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libraries/chain/include/eosio/chain/wasm_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ namespace eosio { namespace chain {
wasm_interface(vm_type vm);
~wasm_interface();

//call before dtor to skip what can be minutes of dtor overhead with some runtimes; can cause leaks
void indicate_shutting_down();

//validates code -- does a WASM validation pass and checks the wasm against EOSIO specific constraints
static void validate(const controller& control, const bytes& code);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ namespace eosio { namespace chain {
EOS_THROW(wasm_exception, "wasm_interface_impl fall through");
}

~wasm_interface_impl() {
if(is_shutting_down)
std::for_each(instantiation_cache.begin(), instantiation_cache.end(), [](auto& i) {i.second.release();});
heifner marked this conversation as resolved.
Show resolved Hide resolved
}

std::vector<uint8_t> parse_initial_memory(const Module& module) {
std::vector<uint8_t> mem_image;

Expand Down Expand Up @@ -89,6 +94,7 @@ namespace eosio { namespace chain {
return it->second;
}

bool is_shutting_down = false;
std::unique_ptr<wasm_runtime_interface> runtime_interface;
map<digest_type, std::unique_ptr<wasm_instantiated_module_interface>> instantiation_cache;
};
Expand Down
4 changes: 4 additions & 0 deletions libraries/chain/wasm_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ namespace eosio { namespace chain {
//Hard: Kick off instantiation in a separate thread at this location
}

void wasm_interface::indicate_shutting_down() {
my->is_shutting_down = true;
}

void wasm_interface::apply( const digest_type& code_id, const shared_string& code, apply_context& context ) {
my->get_instantiated_module(code_id, code, context.trx_context)->apply(context);
}
Expand Down
2 changes: 2 additions & 0 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,8 @@ void chain_plugin::plugin_shutdown() {
my->irreversible_block_connection.reset();
my->accepted_transaction_connection.reset();
my->applied_transaction_connection.reset();
if(app().is_quiting())
my->chain->get_wasm_interface().indicate_shutting_down();
my->chain.reset();
}

Expand Down