Skip to content

Commit c72e60f

Browse files
authored
Fix dropping cached stack with Store::into_data (#10009) (#10014)
This commit fixes a regression from #9604 where using `Store::into_data` wouldn't properly drop a cached stack in a store like a `Drop` destructor. The fix here is to add the `flush_fiber_stack` method into the `into_data` here as well.
1 parent fa6a12d commit c72e60f

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

crates/wasmtime/src/runtime/store.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,8 @@ impl<T> Store<T> {
655655

656656
/// Consumes this [`Store`], destroying it, and returns the underlying data.
657657
pub fn into_data(mut self) -> T {
658+
self.inner.flush_fiber_stack();
659+
658660
// This is an unsafe operation because we want to avoid having a runtime
659661
// check or boolean for whether the data is actually contained within a
660662
// `Store`. The data itself is stored as `ManuallyDrop` since we're

tests/all/pooling_allocator.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -995,16 +995,21 @@ async fn total_stacks_limit() -> Result<()> {
995995
let mut store1 = Store::new(&engine, ());
996996
let instance1 = linker.instantiate_async(&mut store1, &module).await?;
997997
let run1 = instance1.get_func(&mut store1, "run").unwrap();
998-
let future1 = run1.call_async(store1, &[], &mut []);
998+
let future1 = run1.call_async(&mut store1, &[], &mut []);
999999

10001000
let mut store2 = Store::new(&engine, ());
10011001
let instance2 = linker.instantiate_async(&mut store2, &module).await?;
10021002
let run2 = instance2.get_func(&mut store2, "run").unwrap();
1003-
let future2 = run2.call_async(store2, &[], &mut []);
1003+
let future2 = run2.call_async(&mut store2, &[], &mut []);
10041004

10051005
future1.await?;
10061006
future2.await?;
10071007

1008+
// Dispose one store via `Drop`, the other via `into_data`, and ensure that
1009+
// any lingering stacks make their way back to the pool.
1010+
drop(store1);
1011+
store2.into_data();
1012+
10081013
Ok(())
10091014
}
10101015

0 commit comments

Comments
 (0)