Skip to content

Commit 4d171d0

Browse files
authored
Fix some minor mistakes/typos in guest_write (#13210)
* Fix some minor mistakes/typos in `guest_write` This commit fixes a mistake where if a synchronous call to `future.write` was blocked, then it woke up because the readable end was dropped, the future would then erroneously not be marked "done" which could allow future operations to proceed. The fix here is to adjust a `matches!` to handle both futures and streams. An associated `*.wast` test is expanded to mix in synchronous calls as well as asynchronous calls in various places. The test is refactored a bit to have various helpers in various places. Finally some minor updates to error messages are made which avoids saying "stream" when the error shows up for both futures and streams. * Fix tests
1 parent 9dc41f7 commit 4d171d0

4 files changed

Lines changed: 311 additions & 125 deletions

File tree

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3512,7 +3512,7 @@ impl Instance {
35123512
};
35133513

35143514
if done {
3515-
bail!("cannot write to stream after being notified that the readable end dropped");
3515+
bail!("cannot write after being notified that the readable end dropped");
35163516
}
35173517

35183518
*state = TransmitLocalState::Busy;
@@ -3724,10 +3724,7 @@ impl Instance {
37243724
if result != ReturnCode::Blocked {
37253725
*self.id().get_mut(store.0).get_mut_by_index(ty, handle)?.1 =
37263726
TransmitLocalState::Write {
3727-
done: matches!(
3728-
(result, ty),
3729-
(ReturnCode::Dropped(_), TransmitIndex::Stream(_))
3730-
),
3727+
done: matches!(result, ReturnCode::Dropped(_)),
37313728
};
37323729
}
37333730

@@ -3767,7 +3764,7 @@ impl Instance {
37673764
};
37683765

37693766
if done {
3770-
bail!("cannot read from stream after being notified that the writable end dropped");
3767+
bail!("cannot read after being notified that the writable end dropped");
37713768
}
37723769

37733770
*state = TransmitLocalState::Busy;

crates/wast/src/wast.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,10 @@ impl WastContext {
538538
|| (expected.contains("null function") && (actual.contains("uninitialized element") || actual.contains("null reference")))
539539
// GC tests say "null $kind reference" but we just say "null reference".
540540
|| (expected.contains("null") && expected.contains("reference") && actual.contains("null reference"))
541+
// upstream component model tests expect slightly different error
542+
// messages than we generate.
543+
|| (expected.contains("cannot write") && actual.contains("cannot write"))
544+
|| (expected.contains("cannot read") && actual.contains("cannot read"))
541545
{
542546
return Ok(());
543547
}

tests/misc_testsuite/component-model/async/stream-cancel-finished-op.wast

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,23 +229,23 @@
229229
)
230230

231231
(component instance $A $A)
232-
(assert_trap (invoke "test-cancel-read" (u32.const 0)) "cannot read from stream after being notified that the writable end dropped")
232+
(assert_trap (invoke "test-cancel-read" (u32.const 0)) "cannot read after being notified that the writable end dropped")
233233
(component instance $A $A)
234-
(assert_trap (invoke "test-cancel-read" (u32.const 2)) "cannot read from stream after being notified that the writable end dropped")
234+
(assert_trap (invoke "test-cancel-read" (u32.const 2)) "cannot read after being notified that the writable end dropped")
235235
(component instance $A $A)
236-
(assert_trap (invoke "test-cancel-read" (u32.const 3)) "cannot read from stream after being notified that the writable end dropped")
236+
(assert_trap (invoke "test-cancel-read" (u32.const 3)) "cannot read after being notified that the writable end dropped")
237237

238238
(component instance $A $A)
239-
(assert_trap (invoke "test-cancel-write" (u32.const 1)) "cannot write to stream after being notified that the readable end dropped")
239+
(assert_trap (invoke "test-cancel-write" (u32.const 1)) "cannot write after being notified that the readable end dropped")
240240
(component instance $A $A)
241-
(assert_trap (invoke "test-cancel-write" (u32.const 2)) "cannot write to stream after being notified that the readable end dropped")
241+
(assert_trap (invoke "test-cancel-write" (u32.const 2)) "cannot write after being notified that the readable end dropped")
242242
(component instance $A $A)
243-
(assert_trap (invoke "test-cancel-write" (u32.const 3)) "cannot write to stream after being notified that the readable end dropped")
243+
(assert_trap (invoke "test-cancel-write" (u32.const 3)) "cannot write after being notified that the readable end dropped")
244244

245245

246246
(component instance $A $A)
247-
(assert_trap (invoke "test-cancel-future-write" (u32.const 2)) "cannot write to stream after being notified that the readable end dropped")
247+
(assert_trap (invoke "test-cancel-future-write" (u32.const 2)) "cannot write after being notified that the readable end dropped")
248248
(component instance $A $A)
249-
(assert_trap (invoke "test-cancel-future-write" (u32.const 3)) "cannot write to stream after being notified that the readable end dropped")
249+
(assert_trap (invoke "test-cancel-future-write" (u32.const 3)) "cannot write after being notified that the readable end dropped")
250250
(component instance $A $A)
251-
(assert_trap (invoke "test-cancel-future-write" (u32.const 4)) "cannot write to stream after being notified that the readable end dropped")
251+
(assert_trap (invoke "test-cancel-future-write" (u32.const 4)) "cannot write after being notified that the readable end dropped")

0 commit comments

Comments
 (0)