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

Fresh Web Server dies with "Bad resource ID" in Dev Mode #21379

Closed
qkniep opened this issue Nov 29, 2023 · 3 comments · Fixed by #21849
Closed

Fresh Web Server dies with "Bad resource ID" in Dev Mode #21379

qkniep opened this issue Nov 29, 2023 · 3 comments · Fixed by #21849
Assignees
Labels
bug Something isn't working correctly ext/websocket related to the ext/websocket crate

Comments

@qkniep
Copy link

qkniep commented Nov 29, 2023

Version: Deno 1.38.2

I am maintaining a relatively simple web app centered around a single WebSocket endpoint. Recently the server crashed due to an internal panic within the Deno Rust code. This happened during moderate load (~100 concurrent connections). Later I was able to reproduce this in a low load environment (3 clients) without any communication apart from ping messages and connects/disconnects. I do not remember encountering the same problem in previous versions of Deno and haven't materially altered the code base in between.

Not sure if this helps in debugging, but this is some debugging output I produced based on the socket state

ERROR WebSocket errored: Unexpected EOF.
WARNING WebSocket closed.
ERROR WebSocket errored: Unexpected EOF.
WARNING WebSocket closed.
ERROR WebSocket errored: No response from ping frame..
WARNING WebSocket closed.
WARNING Socket not ready (state 3)
WARNING WebSocket closed.
WARNING Socket not ready (state 3)
[...]
WARNING Socket not ready (state 3)
ERROR WebSocket errored: No response from ping frame..
WARNING WebSocket closed.
WARNING Socket not ready (state 3)

This is the entire error output Deno produced:

============================================================
Deno has panicked. This is a bug in Deno. Please report this
at https://github.com/denoland/deno/issues/new.
If you can reliably reproduce this panic, include the
reproduction steps and re-run with the RUST_BACKTRACE=1 env
var set and include the backtrace in your report.

Platform: linux x86_64
Version: 1.38.2
Args: ["/local/home/qkniep/.deno/bin/deno", "run", "-A", "--watch=static/,routes/", "dev.ts"]

thread 'main' panicked at ext/websocket/lib.rs:733:67:
called `Result::unwrap()` on an `Err` value: Bad resource ID
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@qkniep
Copy link
Author

qkniep commented Nov 29, 2023

I was able to reproduce the same bug in the most recent version of Deno (1.38.3) as well and was able to run it with the RUST_BACKTRACE=1 flag (see output below). The basic procedure on the client is: (1) disconnect from internet (2) close website (3) wait for a minute (4) reconnect to the internet (5) reopen website.

By the way, I am also using the fresh framework for this app.

Importantly, I also now noticed that the request to open the _frsh/alive WebSocket fails in step (5). Also, I was so far not able to reproduce the same bug in a production build. So, I now suspect that the crash originates in something related to the _frsh/alive WebSocket and not the WebSockets I am spawning myself.

This is the output when the problem happens while running with RUST_BACKTRACE=1:

============================================================
Deno has panicked. This is a bug in Deno. Please report this
at https://github.com/denoland/deno/issues/new.
If you can reliably reproduce this panic, include the
reproduction steps and re-run with the RUST_BACKTRACE=1 env
var set and include the backtrace in your report.

Platform: linux x86_64
Version: 1.38.3
Args: ["/local/home/qkniep/.deno/bin/deno", "run", "-A", "--watch=static/,routes/", "dev.ts"]

thread 'main' panicked at ext/websocket/lib.rs:733:67:
called `Result::unwrap()` on an `Err` value: Bad resource ID
stack backtrace:
   0: rust_begin_unwind
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/panicking.rs:597:5
   1: core::panicking::panic_fmt
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/result.rs:1652:5
   3: deno_websocket::op_ws_get_buffer_as_string::v8_fn_ptr
   4: Builtins_CallApiCallbackGeneric
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@qkniep qkniep changed the title WebSocket Server dies with "Bad resource ID" Fresh Web Server dies with "Bad resource ID" in Dev Mode Nov 29, 2023
@crowlKats crowlKats added bug Something isn't working correctly ext/websocket related to the ext/websocket crate labels Nov 29, 2023
@littledivy
Copy link
Member

Panic is fixed in 1.39. It should throw a catchable error.

@qkniep
Copy link
Author

qkniep commented Dec 18, 2023

Now (in Deno 1.39.0) the error is indeed thrown as an exception within the JS code. However, I encountered the case where it is thrown inside the WebSocket event loop:

ERROR WebSocket errored: Unexpected EOF.
WARNING WebSocket closed.
error: Uncaught (in promise) BadResource: Bad resource ID
    at WebSocket.[[[eventLoop]]] (ext:deno_websocket/01_websocket.js:424:19)
    at eventLoopTick (ext:core/01_core.js:181:11)

It might be due to my lack of understanding of either Deno or Async JS, but it seems to me that this is not catchable from user-level code and would instead need to be caught within the library code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly ext/websocket related to the ext/websocket crate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants