Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit a5436cc

Browse files
authored
lazily look up state in stream/future event loop (#88)
This fixes a (deterministic) race condition where a `{Stream|Future}{Writer|Reader}` is dropped before the corresponding `start_event_loop` background task has had a chance to run. Fixes #81 Signed-off-by: Joel Dice <joel.dice@fermyon.com>
1 parent 88dd50b commit a5436cc

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,8 @@ impl ComponentInstance {
13811381
fn get_state_rep(instance: SendSyncPtr<ComponentInstance>, rep: u32) -> Result<u32> {
13821382
let instance = unsafe { &mut *instance.as_ptr() };
13831383
Ok(instance
1384-
.get(TableId::<TransmitHandle>::new(rep))?
1384+
.get(TableId::<TransmitHandle>::new(rep))
1385+
.with_context(|| format!("stream or future rep {rep} not found"))?
13851386
.state
13861387
.rep())
13871388
}
@@ -1391,8 +1392,12 @@ impl ComponentInstance {
13911392
{
13921393
let instance = SendSyncPtr::new(NonNull::new(self).unwrap());
13931394
async move {
1394-
let rep = get_state_rep(instance, rep)?;
1395+
let mut my_rep = None;
13951396
while let Some(event) = rx.next().await {
1397+
if my_rep.is_none() {
1398+
my_rep = Some(get_state_rep(instance, rep)?);
1399+
}
1400+
let rep = my_rep.unwrap();
13961401
match event {
13971402
StreamOrFutureEvent::Write {
13981403
values,

0 commit comments

Comments
 (0)