diff --git a/src/wasm.cc b/src/wasm.cc index de1e8e72..823218d8 100644 --- a/src/wasm.cc +++ b/src/wasm.cc @@ -517,11 +517,18 @@ getOrCreateThreadLocalWasm(std::shared_ptr base_wasm, WasmHandleCloneFactory clone_factory) { auto wasm_handle = getThreadLocalWasm(base_wasm->wasm()->vm_key()); if (wasm_handle) { - auto root_context = wasm_handle->wasm()->getOrCreateRootContext(plugin); - if (!wasm_handle->wasm()->configure(root_context, plugin)) { - base_wasm->wasm()->fail(FailState::ConfigureFailed, - "Failed to configure thread-local Wasm code"); - return nullptr; + auto root_context = wasm_handle->wasm()->getRootContext(plugin->key()); + if (!root_context) { + root_context = wasm_handle->wasm()->start(plugin); + if (!root_context) { + base_wasm->wasm()->fail(FailState::StartFailed, "Failed to start thread-local Wasm"); + return nullptr; + } + if (!wasm_handle->wasm()->configure(root_context, plugin)) { + base_wasm->wasm()->fail(FailState::ConfigureFailed, + "Failed to configure thread-local Wasm plugin"); + return nullptr; + } } return wasm_handle; }