Skip to content

Commit 8e4ac6f

Browse files
committed
std.Build.WebServer: ignore client->server messages on Windows
This is a workaround for a standard library bug which will be resolved by some upcoming writergate rewrite work. I will open a follow-up issue before this PR is merged.
1 parent a4fa8c9 commit 8e4ac6f

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lib/std/Build/WebServer.zig

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,20 @@ fn serveWebSocket(ws: *WebServer, sock: *std.http.WebSocket) !noreturn {
290290
copy.* = @atomicLoad(u8, shared, .monotonic);
291291
}
292292

293-
// TODO: running `recv` on a separate thread happens to be safe with this particular API. It's
294-
// still a horrible hack which should be deleted. Friends don't let friends use threads for IO.
295-
_ = try std.Thread.spawn(.{}, recvWebSocketMessages, .{ ws, sock });
293+
if (builtin.os.tag == .windows) {
294+
// At the time of writing, reading from a socket on Windows on one thread seems to cause
295+
// writes to it from another thread to deadlock. That's *probably* because the current path
296+
// ends up using `ReadFile` instead of the WSA functions. Once writergate is merged, we'll
297+
// be using the proper functions, so should be able to enable this.
298+
std.log.warn("implementation currently ignores client messages on Windows; the 'Rebuild' button will do nothing", .{});
299+
} else {
300+
// TODO: the `std.http.WebSocket` API should include guarantees that receiving messages on
301+
// one thread while another sends them is okay. At the time of writing, it is, but it should
302+
// be documented as such, because this use case is important! This will become particularly
303+
// relevant once we implement `std.Io`, so that concurrent tasks -- potentially on different
304+
// threads depending on the `Io` implementation -- become the blessed way to achieve this.
305+
_ = try std.Thread.spawn(.{}, recvWebSocketMessages, .{ ws, sock });
306+
}
296307

297308
{
298309
const hello_header: abi.Hello = .{

0 commit comments

Comments
 (0)