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 all commits
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 @@ -79,6 +79,9 @@ namespace eosio { namespace chain {
wasm_interface(vm_type vm, const chainbase::database& db);
~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 @@ -46,6 +46,14 @@ namespace eosio { namespace chain {
EOS_THROW(wasm_exception, "wasm_interface_impl fall through");
}

~wasm_interface_impl() {
if(is_shutting_down)
for(wasm_cache_index::iterator it = wasm_instantiation_cache.begin(); it != wasm_instantiation_cache.end(); ++it)
wasm_instantiation_cache.modify(it, [](wasm_cache_entry& e) {
e.module.release();
});
}

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

Expand Down Expand Up @@ -136,6 +144,7 @@ namespace eosio { namespace chain {
return it->module;
}

bool is_shutting_down = false;
std::unique_ptr<wasm_runtime_interface> runtime_interface;

typedef boost::multi_index_container<
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 @@ -57,6 +57,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::code_block_num_last_used(const digest_type& code_hash, const uint8_t& vm_type, const uint8_t& vm_version, const uint32_t& block_num) {
my->code_block_num_last_used(code_hash, vm_type, vm_version, block_num);
}
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 @@ -996,6 +996,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