Skip to content

Commit ee2a603

Browse files
author
Mark McCaskey
committed
Document potential deadlock in extension of WASI, deprecate state_mut
1 parent a443f54 commit ee2a603

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
### Changed
1616

17+
- [#1838](https://github.com/wasmerio/wasmer/pull/1838) Deprecate `WasiEnv::state_mut`: prefer `WasiEnv::state` instead.
1718
- [#1663](https://github.com/wasmerio/wasmer/pull/1663) Function environments passed to host functions now must be passed by `&` instead of `&mut`. This is a breaking change. This change fixes a race condition when a host function is called from multiple threads. If you need mutability in your environment, consider using `std::sync::Mutex` or other synchronization primitives.
1819
- [#1830](https://github.com/wasmerio/wasmer/pull/1830) Minimum supported Rust version bumped to 1.47.0
1920
- [#1810](https://github.com/wasmerio/wasmer/pull/1810) Make the `state` field of `WasiEnv` public

lib/wasi/src/lib.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ pub enum WasiError {
5454
pub struct WasiEnv {
5555
/// Shared state of the WASI system. Manages all the data that the
5656
/// executing WASI program can see.
57+
///
58+
/// Be careful when using this in host functions that call into Wasm:
59+
/// if the lock is held and the Wasm calls into a host function that tries
60+
/// to lock this mutex, the program will deadlock.
5761
pub state: Arc<Mutex<WasiState>>,
5862
memory: Arc<WasiMemory>,
5963
}
@@ -163,11 +167,17 @@ impl WasiEnv {
163167
}
164168

165169
/// Get the WASI state
170+
///
171+
/// Be careful when using this in host functions that call into Wasm:
172+
/// if the lock is held and the Wasm calls into a host function that tries
173+
/// to lock this mutex, the program will deadlock.
166174
pub fn state(&self) -> MutexGuard<WasiState> {
167175
self.state.lock().unwrap()
168176
}
169177

170-
/// Get the WASI state (mutable)
178+
// TODO: delete this method before 1.0.0 release
179+
#[doc(hidden)]
180+
#[deprecated(since = "1.0.0-beta1", note = "Please use the `state` method instead")]
171181
pub fn state_mut(&mut self) -> MutexGuard<WasiState> {
172182
self.state.lock().unwrap()
173183
}

0 commit comments

Comments
 (0)