deno-websocket icon indicating copy to clipboard operation
deno-websocket copied to clipboard

Crash: request is not acceptable in server

Open LuisMayo opened this issue 3 years ago • 4 comments

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/[email protected]/example/server.ts
  2. Open http://localhost:8080/
  3. Now the server has crashed

Thanks.

LuisMayo avatar Oct 13 '20 14:10 LuisMayo

Thank you for your issue.

OK. I will support it.

ryo-ma avatar Oct 14 '20 23:10 ryo-ma

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/[email protected]/ws/mod.ts:453:9)
    at WebSocketServer.connect (https://deno.land/x/[email protected]/lib/websocket.ts:35:28)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `sh run.sh`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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

Josema avatar Jun 20 '21 16:06 Josema

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

UserJHansen avatar Aug 27 '21 03:08 UserJHansen

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

Josema avatar Aug 27 '21 09:08 Josema