Skip to content

Commit 8628263

Browse files
committed
chore: Use fatalError in all .wait() calls for WASI builds only. The existing blocking call in wait() will cause wasm executables to trap with an ambiguous message. This improves the message to help developers understand and correct the issue.
1 parent fa91d79 commit 8628263

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Sources/NIOCore/EventLoopFuture.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,26 @@ extension EventLoopFuture {
10911091
@preconcurrency
10921092
@inlinable
10931093
public func wait(file: StaticString = #file, line: UInt = #line) throws -> Value where Value: Sendable {
1094+
#if os(WASI)
1095+
// NOTE: As of July 22, 2025 `wait()` calling wait() is not supported on WASI platforms.
1096+
//
1097+
// This may change down the road if and when true multi-threading evolves. But right now
1098+
// calling wait here results in the following runtime crash:
1099+
//
1100+
// ```
1101+
// SomeExecutable.wasm:0x123456 Uncaught (in promise) RuntimeError: Atomics.wait cannot be called in this context
1102+
// ```
1103+
//
1104+
// Using the following fatal error here gives wasm runtime users a much more clear error message
1105+
// to identify the issue.
1106+
//
1107+
// If you're running into this error on WASI, refactoring to `get()` instead of `wait()` will
1108+
// likely solve the issue.
1109+
fatalError(
1110+
"NIO's wait() function should not be called on WASI platforms. It will freeze or crash. Use get() instead."
1111+
)
1112+
#endif // os(WASI)
1113+
10941114
try self._blockingWaitForFutureCompletion(file: file, line: line)
10951115
}
10961116

0 commit comments

Comments
 (0)