From 47b563db0d7505bbf98c1044a8b0329a067428ce Mon Sep 17 00:00:00 2001 From: Scott Marchant Date: Wed, 22 Oct 2025 12:05:02 -0600 Subject: [PATCH] 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. --- Sources/NIOCore/EventLoopFuture.swift | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Sources/NIOCore/EventLoopFuture.swift b/Sources/NIOCore/EventLoopFuture.swift index ddf891bedb..18ac53c23c 100644 --- a/Sources/NIOCore/EventLoopFuture.swift +++ b/Sources/NIOCore/EventLoopFuture.swift @@ -1073,6 +1073,26 @@ extension EventLoopFuture { @preconcurrency @inlinable public func wait(file: StaticString = #file, line: UInt = #line) throws -> Value where Value: Sendable { + #if os(WASI) + // NOTE: As of July 22, 2025 `wait()` calling wait() is not supported on WASI platforms. + // + // This may change down the road if and when true multi-threading evolves. But right now + // calling wait here results in the following runtime crash: + // + // ``` + // SomeExecutable.wasm:0x123456 Uncaught (in promise) RuntimeError: Atomics.wait cannot be called in this context + // ``` + // + // Using the following fatal error here gives wasm runtime users a much more clear error message + // to identify the issue. + // + // If you're running into this error on WASI, refactoring to `get()` instead of `wait()` will + // likely solve the issue. + fatalError( + "NIO's wait() function should not be called on WASI platforms. It will freeze or crash. Use get() instead." + ) + #endif // os(WASI) + try self._blockingWaitForFutureCompletion(file: file, line: line) }