denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
93.99k stars 5.23k forks source link

deno_cache panics when using `compile` #18889

Open felix-schindler opened 1 year ago

felix-schindler commented 1 year ago

General information

The panic occurs when using the cache function of x/hono@v3.1.6/middleware.ts and only when using the compile command. When running directly, it seems to be working just fine.

Rust Backtrace

using Docker (denoland/deno:alpine)

============================================================
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.33.0
Args: ["./backend"]

thread 'main' panicked at 'required type deno_cache::CreateCache<deno_cache::sqlite::SqliteBackedCache> is not present in GothamState container', /home/runner/work/deno/deno/core/gotham_state.rs:82:3
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/panicking.rs:64:14
   2: deno_core::gotham_state::missing
   3: deno_cache::get_cache
   4: <futures_util::future::future::Map<Fut,F> as core::future::future::Future>::poll
   5: deno_core::runtime::queue_async_op
   6: deno_cache::op_cache_storage_open::v8_fn_ptr
   7: _ZN2v88internal12_GLOBAL__N_119HandleApiCallHelperILb0EEENS0_11MaybeHandleINS0_6ObjectEEEPNS0_7IsolateENS0_6HandleINS0_10HeapObjectEEENS8_INS0_20FunctionTemplateInfoEEENS8_IS4_EEPmi
             at ./../../../../v8/src/builtins/builtins-api.cc:113:36
   8: _ZN2v88internal21Builtin_HandleApiCallEiPmPNS0_7IsolateE
             at ./../../../../v8/src/builtins/builtins-api.cc:135:1
   9: Builtins_CEntry_Return1_ArgvOnStack_BuiltinExit
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

using macOS

============================================================
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: macos x86_64
Version: 1.32.5
Args: ["./backend"]

thread 'main' panicked at 'required type deno_cache::CreateCache<deno_cache::sqlite::SqliteBackedCache> is not present in GothamState container', /private/tmp/deno-20230419-9141-3g7nb7/deno/core/gotham_state.rs:82:3
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: deno_core::gotham_state::missing
   3: deno_cache::get_cache
   4: deno_cache::op_cache_storage_open::v8_func::{{closure}}
   5: <futures_util::future::maybe_done::MaybeDone<Fut> as core::future::future::Future>::poll
   6: deno_cache::op_cache_storage_open::v8_fn_ptr
   7: __ZN2v88internal12_GLOBAL__N_119HandleApiCallHelperILb0EEENS0_11MaybeHandleINS0_6ObjectEEEPNS0_7IsolateENS0_6HandleINS0_10HeapObjectEEENS8_INS0_20FunctionTemplateInfoEEENS8_IS4_EEPmi
   8: __ZN2v88internal21Builtin_HandleApiCallEiPmPNS0_7IsolateE
Leokuma commented 8 months ago

Smaller reproducible example:

// app.ts
await caches.open('my-cache');
❯ deno compile -Ar app.ts
❯ RUST_BACKTRACE=full ./app                                                                                                                  17:31:59

============================================================
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.39.2
Args: ["./app"]

thread 'main' panicked at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/deno_core-0.243.0/gotham_state.rs:82:3:
required type deno_cache::CreateCache<deno_cache::sqlite::SqliteBackedCache> is not present in GothamState container
stack backtrace:
   0:     0x5648094f3aec - std::backtrace_rs::backtrace::libunwind::trace::ha637c64ce894333a
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x5648094f3aec - std::backtrace_rs::backtrace::trace_unsynchronized::h47f62dea28e0c88d
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x5648094f3aec - std::sys_common::backtrace::_print_fmt::h9eef0abe20ede486
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x5648094f3aec - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hed7f999df88cc644
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x564809528fa0 - core::fmt::rt::Argument::fmt::h1539a9308b8d058d
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/fmt/rt.rs:142:9
   5:     0x564809528fa0 - core::fmt::write::h3a39390d8560d9c9
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/fmt/mod.rs:1120:17
   6:     0x5648094ed8ef - std::io::Write::write_fmt::h5fc9997dfe05f882
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/io/mod.rs:1762:15
   7:     0x5648094f38d4 - std::sys_common::backtrace::_print::h894006fb5c6f3d45
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x5648094f38d4 - std::sys_common::backtrace::print::h23a2d212c6fff936
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x5648094f5597 - std::panicking::default_hook::{{closure}}::h8a1d2ee00185001a
  10:     0x5648094f52ff - std::panicking::default_hook::h6038f2eba384e475
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:292:9
  11:     0x5648099bbfea - deno::setup_panic_hook::{{closure}}::hacc44a02420c7519
  12:     0x5648094f5c18 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h1f8f335eaa9cfaee
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/alloc/src/boxed.rs:2021:9
  13:     0x5648094f5c18 - std::panicking::rust_panic_with_hook::h2b5517d590cab22e
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:783:13
  14:     0x5648094f596e - std::panicking::begin_panic_handler::{{closure}}::h233112c06e0ef43e
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:657:13
  15:     0x5648094f3fb6 - std::sys_common::backtrace::__rust_end_short_backtrace::h6e893f24d7ebbff8
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs:170:18
  16:     0x5648094f56d2 - rust_begin_unwind
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:645:5
  17:     0x564809526025 - core::panicking::panic_fmt::hbf0e066aabfa482c
                               at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:72:14
  18:     0x56480a15e8d2 - deno_core::gotham_state::missing::hdc17e0b5b1bb5488
  19:     0x564809ddcb52 - deno_cache::get_cache::h9bb2f2c062ca72c9
  20:     0x564809dd96ff - deno_cache::op_cache_storage_open<CA>::call::{{closure}}::hd7ea88e226849057
  21:     0x564809dd9cc4 - deno_cache::op_cache_storage_open<CA>::v8_fn_ptr::h068eab352b334d85
  22:     0x56480930895d - Builtins_CallApiCallbackGeneric
mmastrac commented 6 months ago

The problem appears to be that we are using StorageKeyResolver::empty() in cli/standalone/mod.rs which disables the cache.

What probably needs to happen here is that we should use the current executing path (aka argv[0]) of the compiled executable as the key. This should fix the cache API.

This will also need an associated test.