Skip to content

Commit 47b563d

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 89be322 commit 47b563d

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
@@ -1073,6 +1073,26 @@ extension EventLoopFuture {
10731073
@preconcurrency
10741074
@inlinable
10751075
public func wait(file: StaticString = #file, line: UInt = #line) throws -> Value where Value: Sendable {
1076+
#if os(WASI)
1077+
// NOTE: As of July 22, 2025 `wait()` calling wait() is not supported on WASI platforms.
1078+
//
1079+
// This may change down the road if and when true multi-threading evolves. But right now
1080+
// calling wait here results in the following runtime crash:
1081+
//
1082+
// ```
1083+
// SomeExecutable.wasm:0x123456 Uncaught (in promise) RuntimeError: Atomics.wait cannot be called in this context
1084+
// ```
1085+
//
1086+
// Using the following fatal error here gives wasm runtime users a much more clear error message
1087+
// to identify the issue.
1088+
//
1089+
// If you're running into this error on WASI, refactoring to `get()` instead of `wait()` will
1090+
// likely solve the issue.
1091+
fatalError(
1092+
"NIO's wait() function should not be called on WASI platforms. It will freeze or crash. Use get() instead."
1093+
)
1094+
#endif // os(WASI)
1095+
10761096
try self._blockingWaitForFutureCompletion(file: file, line: line)
10771097
}
10781098

0 commit comments

Comments
 (0)