{"record":{"id":"b0172981f4a531a2","repo":"wasmerio/wasmer","slug":"internal-error-module-with-handle-module-handle","errorCode":null,"errorMessage":"Internal error: Module with handle {module_handle:?} was already instantiated in this group","messagePattern":"Internal error: Module with handle (.+?) was already instantiated in this group","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/wasix/src/state/linker/instance_group/table.rs","lineNumber":104,"sourceCode":"            let existing = table.get(store, index).unwrap();\n            if let Value::FuncRef(Some(_)) = existing {\n                panic!(\"Internal error: function table index {index} already occupied\");\n            }\n        }\n\n        let ty = func.ty(store).to_string();\n        trace!(?index, ?ty, \"Placing function in table at index\");\n        table.set(store, index, Value::FuncRef(Some(func)))\n    }\n\n    pub(super) fn allocate_function_table_for_existing_module(\n        &mut self,\n        linker_state: &LinkerState,\n        store: &mut impl AsStoreMut,\n        module_handle: ModuleHandle,\n    ) -> Result<(), LinkError> {\n        if self.side_instances.contains_key(&module_handle) {\n            panic!(\n                \"Internal error: Module with handle {module_handle:?} \\\n                was already instantiated in this group\"\n            )\n        };\n\n        let dl_module = linker_state\n            .side_modules\n            .get(&module_handle)\n            .expect(\"Internal error: module not loaded into linker\");\n\n        let table_base = self\n            .allocate_function_table(\n                store,\n                dl_module.dylink_info.mem_info.table_size,\n                dl_module.dylink_info.mem_info.table_alignment,\n            )\n            .map_err(LinkError::TableAllocationError)?;\n","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/wasmerio/wasmer/blob/8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5/lib/wasix/src/state/linker/instance_group/table.rs#L86-L122","documentation":"allocate_function_table_for_existing_module panics if the given ModuleHandle is already present in the group's side_instances map. Each module in a dynamic-linking group must be instantiated at most once; re-instantiating the same handle would allocate duplicate table/memory regions and corrupt the group state.","triggerScenarios":"apply_dl_operation issuing a load/instantiate for a module handle that was already instantiated in this instance group; dlopen called twice for the same module without deduplication; replaying an operation log that contains a duplicate load.","commonSituations":"Application code calling dlopen on the same .so twice expecting a fresh instance; a dynamic loader replaying DL operations after a partial failure and retry without state reset.","solutions":["Deduplicate dlopen calls: check whether the module is already loaded in the group before requesting instantiation","Reset/rebuild the InstanceGroup if you intentionally want a fresh instantiation of the same module","Ensure dlopen caching semantics are honored (same path returns the same handle, not a new load)"],"exampleFix":"// before\nlet h = runtime.dlopen(\"libfoo.so\")?;\nlet h2 = runtime.dlopen(\"libfoo.so\")?; // panics on second instantiate\n// after\nlet h = runtime.dlopen(\"libfoo.so\")?;\n// reuse h for subsequent calls; dlopen is idempotent per group","handlingStrategy":"validation","validationCode":"fn can_instantiate(group: &InstanceGroup, h: &ModuleHandle) -> bool {\n    !group.side_instances.contains_key(h)\n}\n// before apply_dl_operation: assert!(can_instantiate(&group, &handle));","typeGuard":"fn is_fresh_handle(h: &ModuleHandle, loaded: &HashSet<ModuleHandle>) -> bool {\n    !loaded.contains(h)\n}","tryCatchPattern":null,"preventionTips":["Cache dlopen results by path and reuse the existing handle","Reset the InstanceGroup before replaying load operations","Treat dlopen as idempotent per group","Track loaded handles explicitly in your loader wrapper"],"tags":["linker","duplicate-instantiation","dlopen","panic"],"backgroundTag":"module-already-instantiated","analyzedSha":"8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5","analyzedAt":"2026-09-01T23:06:31.009Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}