ryo-ma / deno-websocket

🦕 A simple WebSocket library like ws of node.js library for deno
https://deno.land/x/websocket
MIT License
152 stars 17 forks source link

Crash: request is not acceptable in server #11

Open LuisMayo opened 3 years ago

LuisMayo commented 3 years ago

Hi and thanks for this library, it really ease things up.

I have detected that when you use WebSocketServer and go and try to establish an HTTP connection to the websocket port the server crashes and closes.

While I obviously don't expect the WS server to work properly when being contacted by the wrong protocol it should fail silently, or at least, allow the programmer to specify an error callback in case things like this occur.

I know that the error is indeed generated by Deno's std library ws. However I think if possible it should be handled here.

Steps to reproduce

  1. deno run --allow-net https://deno.land/x/websocket@v0.0.5/example/server.ts
  2. Open http://localhost:8080/
  3. Now the server has crashed

Thanks.

ryo-ma commented 3 years ago

Thank you for your issue.

OK. I will support it.

Josema commented 3 years ago

Same issue here. It makes the app crashes.

error: Uncaught (in promise) Error: request is not acceptable
  throw new Error("request is not acceptable");
        ^
    at acceptWebSocket (https://deno.land/std@0.92.0/ws/mod.ts:453:9)
    at WebSocketServer.connect (https://deno.land/x/websocket@v0.1.2/lib/websocket.ts:35:28)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! server@1.0.0 start: `sh run.sh`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the server@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ubuntu/.npm/_logs/2021-06-20T16_17_35_643Z-debug.log
UserJHansen commented 2 years ago

You can just do something like: WebsocketServer.on("error", console.log) That will catch all errors like this and just log them to console,

Josema commented 2 years ago

Just using native WebSockets. https://deno.com/blog/v1.12#server-side-websocket-support-in-native-http