Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion include/proxy-wasm/null_vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct NullVm : public WasmVm {

// WasmVm
std::string_view runtime() override { return "null"; }
Cloneable cloneable() override { return Cloneable::InstantiatedModule; };
Cloneable cloneable() override;
std::unique_ptr<WasmVm> clone() override;
bool load(const std::string &code, bool allow_precompiled) override;
AbiVersion getAbiVersion() override;
Expand Down
1 change: 1 addition & 0 deletions include/proxy-wasm/null_vm_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class NullVmPlugin {
FOR_ALL_WASM_VM_EXPORTS(_DEFINE_GET_FUNCTION)
#undef _DEFIN_GET_FUNCTIONE

virtual Cloneable cloneable() { return Cloneable::InstantiatedModule; }
WasmVm *wasm_vm_ = nullptr;
};

Expand Down
6 changes: 5 additions & 1 deletion include/proxy-wasm/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,11 @@ class WasmHandleBase : public std::enable_shared_from_this<WasmHandleBase> {
}
}

void kill() { wasm_base_ = nullptr; }
void kill() {
wasm_base_->startShutdown();
wasm_base_->finishShutdown();
wasm_base_ = nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling finishShutdown() immediatelly after startShutdown(), without waiting for the plugin to call proxy_done is technically incorrect, and effectlively a no-op. This sequence works only if the plugin returns true from the proxy_on_done callback, in which case you don't even need to call finishShutdown().

It also breaks the promise of not executing anything in the canary (e.g. you can imagine plugins sending batch reports on shutdown, etc.), which is why we're simply dropping the VM right now.

}

std::shared_ptr<WasmBase> &wasm() { return wasm_base_; }

Expand Down
7 changes: 7 additions & 0 deletions src/null/null_vm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ RegisterNullVmPluginFactory::RegisterNullVmPluginFactory(std::string_view name,
(*null_vm_plugin_factories_)[std::string(name)] = factory;
}

Cloneable NullVm::cloneable() {
if (!plugin_) {
return Cloneable::NotCloneable;
}
return plugin_->cloneable();
}

std::unique_ptr<WasmVm> NullVm::clone() {
auto cloned_null_vm = std::make_unique<NullVm>(*this);
if (integration())
Expand Down
2 changes: 1 addition & 1 deletion test/null_vm_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ TEST_F(BaseVmTest, NullVmStartup) {
auto wasm_vm = createNullVm();
EXPECT_TRUE(wasm_vm != nullptr);
EXPECT_TRUE(wasm_vm->runtime() == "null");
EXPECT_TRUE(wasm_vm->cloneable() == Cloneable::InstantiatedModule);
auto wasm_vm_clone = wasm_vm->clone();
EXPECT_TRUE(wasm_vm_clone != nullptr);
EXPECT_TRUE(wasm_vm->getCustomSection("user").empty());
EXPECT_TRUE(wasm_vm->load("test_null_vm_plugin", true));
EXPECT_TRUE(wasm_vm->cloneable() == Cloneable::InstantiatedModule);
EXPECT_NE(test_null_vm_plugin, nullptr);
}

Expand Down