@@ -210,7 +210,7 @@ WasmBase::WasmBase(const std::shared_ptr<WasmHandleBase> &base_wasm_handle, Wasm
210
210
if (!wasm_vm_) {
211
211
failed_ = FailState::UnableToCreateVm;
212
212
} else {
213
- wasm_vm_->setFailCallback ([this ](FailState fail_state) { failed_ = fail_state; });
213
+ wasm_vm_->addFailCallback ([this ](FailState fail_state) { failed_ = fail_state; });
214
214
}
215
215
}
216
216
@@ -224,7 +224,7 @@ WasmBase::WasmBase(std::unique_ptr<WasmVm> wasm_vm, std::string_view vm_id,
224
224
if (!wasm_vm_) {
225
225
failed_ = FailState::UnableToCreateVm;
226
226
} else {
227
- wasm_vm_->setFailCallback ([this ](FailState fail_state) { failed_ = fail_state; });
227
+ wasm_vm_->addFailCallback ([this ](FailState fail_state) { failed_ = fail_state; });
228
228
}
229
229
}
230
230
@@ -561,6 +561,14 @@ getOrCreateThreadLocalWasm(std::shared_ptr<WasmHandleBase> base_handle,
561
561
return nullptr ;
562
562
}
563
563
local_wasms[vm_key] = wasm_handle;
564
+ wasm_handle->wasm ()->wasm_vm ()->addFailCallback ([vm_key](proxy_wasm::FailState fail_state) {
565
+ if (fail_state == proxy_wasm::FailState::RuntimeError) {
566
+ // If VM failed, erase the entry so that:
567
+ // 1) we can recreate the new thread local VM from the same base_wasm.
568
+ // 2) we wouldn't reuse the failed VM for new plugins accidentally.
569
+ local_wasms.erase (vm_key);
570
+ };
571
+ });
564
572
return wasm_handle;
565
573
}
566
574
@@ -596,6 +604,14 @@ std::shared_ptr<PluginHandleBase> getOrCreateThreadLocalPlugin(
596
604
}
597
605
auto plugin_handle = plugin_factory (wasm_handle, plugin);
598
606
local_plugins[key] = plugin_handle;
607
+ wasm_handle->wasm ()->wasm_vm ()->addFailCallback ([key](proxy_wasm::FailState fail_state) {
608
+ if (fail_state == proxy_wasm::FailState::RuntimeError) {
609
+ // If VM failed, erase the entry so that:
610
+ // 1) we can recreate the new thread local plugin from the same base_wasm.
611
+ // 2) we wouldn't reuse the failed VM for new plugin configs accidentally.
612
+ local_plugins.erase (key);
613
+ };
614
+ });
599
615
return plugin_handle;
600
616
}
601
617
0 commit comments