Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket close code always 1005 #27566

Closed
den9yon9 opened this issue Jan 6, 2025 · 1 comment · Fixed by #27578
Closed

WebSocket close code always 1005 #27566

den9yon9 opened this issue Jan 6, 2025 · 1 comment · Fixed by #27578

Comments

@den9yon9
Copy link

den9yon9 commented Jan 6, 2025

Version: Deno 2.1.4

Deno.serve({ port: 8000, hostname: "127.0.0.1" }, (req) => {
  const { socket, response } = Deno.upgradeWebSocket(req);
  socket.addEventListener("close", (e) => {
    // e.code always 1005
    console.log(`server socket close code: ${e.code}`);
  });
  return response;
});

const socket = new WebSocket("ws://127.0.0.1:8000");

setTimeout(() => {
  socket.close(1000);
}, 3000);

socket.addEventListener("close", (e) => {
  // e.code always 1005
  console.log(`client socket close code: ${e.code}`);
});
@siaeyy
Copy link
Contributor

siaeyy commented Jan 7, 2025

What's more interesting is that if you specify the reason parameter, the code will be handled properly.

littledivy added a commit that referenced this issue Jan 8, 2025
Fixes #27566

The close code wasn't sent if reason was None, defaulting to 1005. This
patch allows sending close code without reason.
dsherret pushed a commit that referenced this issue Jan 9, 2025
Fixes #27566

The close code wasn't sent if reason was None, defaulting to 1005. This
patch allows sending close code without reason.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants