From 316fd43f8f38fdcb9be02d4008a516f9c6b8234f Mon Sep 17 00:00:00 2001 From: Marco Neumann Date: Tue, 10 Mar 2026 13:22:21 +0100 Subject: [PATCH 1/2] test: illustrate #12465 --- tests/all/component_model/resources.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/all/component_model/resources.rs b/tests/all/component_model/resources.rs index 9b99e0d766d3..def0e2a728ca 100644 --- a/tests/all/component_model/resources.rs +++ b/tests/all/component_model/resources.rs @@ -191,6 +191,26 @@ fn resource_any() -> Result<()> { ); } + { + let mut store = Store::new(&engine, ()); + let i = linker.instantiate(&mut store, &c)?; + let t_ctor = i.get_typed_func::<(u32,), (ResourceAny,)>(&mut store, "[constructor]t")?; + let t_dtor = i.get_typed_func::<(ResourceAny,), ()>(&mut store, "drop-t")?; + + // `t0` is placed at host index 0 + let (t0,) = t_ctor.call(&mut store, (100,))?; + t_dtor.call(&mut store, (t0,))?; + + // `t1` is also placed at host index 0 since `t0` was deallocated + let (_t1,) = t_ctor.call(&mut store, (100,))?; + + // reuse of `t0` should fail, despite it pointing to a valid resource + assert_eq!( + t_dtor.call(&mut store, (t0,)).unwrap_err().to_string(), + "host-owned resource is being used with the wrong type" + ); + } + Ok(()) } From 2e7fea0d44e8b7ac0bb8acff244d5c9874d2de29 Mon Sep 17 00:00:00 2001 From: Marco Neumann Date: Tue, 10 Mar 2026 13:27:18 +0100 Subject: [PATCH 2/2] refactor: clarify error msg. for de-allocated `ResourceAny` The error message used to state that this happens because the type of the resource changed, but actually this can also happen with the very same type if the resource was already de-allocated. Clarifying the error message might safe some `wasmtime` users some long debugging sessions. See #12465. --- .../wasmtime/src/runtime/component/resources/host_tables.rs | 2 +- tests/all/component_model/resources.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/wasmtime/src/runtime/component/resources/host_tables.rs b/crates/wasmtime/src/runtime/component/resources/host_tables.rs index 625035296bde..8b83e1b58acd 100644 --- a/crates/wasmtime/src/runtime/component/resources/host_tables.rs +++ b/crates/wasmtime/src/runtime/component/resources/host_tables.rs @@ -177,7 +177,7 @@ impl<'a> HostResourceTables<'a> { // precise error, such as a lift operation. if let Some(actual) = actual { if actual.generation != idx.generation() { - bail!("host-owned resource is being used with the wrong type"); + bail!("host-owned resource was already de-allocated"); } } diff --git a/tests/all/component_model/resources.rs b/tests/all/component_model/resources.rs index def0e2a728ca..6f1fed7895ba 100644 --- a/tests/all/component_model/resources.rs +++ b/tests/all/component_model/resources.rs @@ -187,7 +187,7 @@ fn resource_any() -> Result<()> { // reuse of `t` should fail, despite it pointing to a valid resource assert_eq!( t_dtor.call(&mut store, (t,)).unwrap_err().to_string(), - "host-owned resource is being used with the wrong type" + "host-owned resource was already de-allocated" ); } @@ -207,7 +207,7 @@ fn resource_any() -> Result<()> { // reuse of `t0` should fail, despite it pointing to a valid resource assert_eq!( t_dtor.call(&mut store, (t0,)).unwrap_err().to_string(), - "host-owned resource is being used with the wrong type" + "host-owned resource was already de-allocated" ); }