WebSocket regression in v.2.5.1
ansemjo opened this issue · 4 comments
With the upgrade to Deno v.2.5.1, some WebSocket connections immediately fail with an Error without the request ever reaching the server, it seems. If I downgrade to v2.5.0 using sudo deno upgrade --version 2.5.0 it works as expected again.
Deno v2.5.1
$ deno
Deno 2.5.1
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> new WebSocket('ws://localhost:4080/api/provider/ws').addEventListener("error", err => console.error(err.error));
undefined
> NetworkError: failed to connect to WebSocket: Invalid status code: 400
Interestingly, the echo server works though:
new WebSocket('wss://echo.websocket.org').addEventListener("open", ok => console.log(ok.target.readyState));
undefined
> 1
I have no proxies configured but I would assume it has something to do with either #30700 or #30692?
Deno v2.5.0 (or earlier)
$ deno
Deno 2.5.0
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> new WebSocket('ws://localhost:4080/api/provider/ws').addEventListener("error", err => console.error(err.error));
undefined
Do you have an example of an implementation of the server that is not working?
This example is working for me:
// server.ts
Deno.serve((req) => {
const { socket, response } = Deno.upgradeWebSocket(req);
socket.onopen = () => console.log("socket opened");
socket.onmessage = (e) => {
console.log("socket message:", e.data);
socket.send(e.data);
};
socket.onerror = (e) => console.log("socket error:", e.message);
socket.onclose = () => console.log("socket closed");
return response;
});// client.ts
const ws = new WebSocket("ws://localhost:8000/");
ws.onopen = () => {
console.log("socket opened");
ws.send("hello");
};
ws.onmessage = (e) => {
console.log("socket message:", e.data);
ws.close();
};
ws.onerror = (e) => console.log("socket error:", (e as ErrorEvent).message);
ws.onclose = () => console.log("socket closed");/m/a/P/g/d/deno ❯❯❯ deno run -A server.ts
Listening on http://0.0.0.0:8000/ (http://localhost:8000/)
socket opened
socket message: hello
socket closed
/m/a/P/g/d/deno ❯❯❯ deno run -A client.ts
socket opened
socket message: hello
socket closed
It's from this project: https://github.com/wasimoff/wasimoff
Can be started from a fresh clone using Go:
cd broker/
go run ./
This server also runs on https://wasi.team and this also doesn't work:
$ deno
Deno 2.5.1
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> new WebSocket('wss://wasi.team/api/provider/ws').addEventListener("error", err => console.error(err.error));
undefined
> NetworkError: failed to connect to WebSocket: Invalid status code 400 Bad Request
This sounds like there's something wrong in my server implementation at first but the only thing that changed between those two tests was the Deno version ...
Small note about testing against that server: the connection will close right after because you need to specify a correct protocol as well (seen here). But at least in that case the connection should close normally and not with an error upon connection.
Found the issue - we stopped sending the User-Agent by accident.