1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

fix(core): restore cache journal mode to TRUNCATE and tweak tokio test in CacheDB (#18469)

Fast-follow on #18401 -- the reason that some tests were panicking in
the `CacheDB` `impl Drop` was that the cache itself was being dropped
during panic and the runtime may or may not still exist at that point.
We can reduce the actual tokio runtime testing to where it's needed.

In addition, we return the journal mode to `TRUNCATE` to avoid the risk
of data corruption.
This commit is contained in:
Matt Mastracci 2023-03-28 14:06:57 -06:00 committed by GitHub
parent 35fd8583ef
commit c65149c0a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -39,7 +39,7 @@ impl CacheDBConfiguration {
fn create_combined_sql(&self) -> String { fn create_combined_sql(&self) -> String {
format!( format!(
" "
PRAGMA journal_mode=OFF; PRAGMA journal_mode=TRUNCATE;
PRAGMA synchronous=NORMAL; PRAGMA synchronous=NORMAL;
PRAGMA temp_store=memory; PRAGMA temp_store=memory;
PRAGMA page_size=4096; PRAGMA page_size=4096;
@ -83,7 +83,8 @@ impl Drop for CacheDB {
_ => return, _ => return,
}; };
// TODO(mmastrac): we should ensure tokio runtimes are consistently available or not // If Deno is panicking, tokio is sometimes gone before we have a chance to shutdown. In
// that case, we just allow the drop to happen as expected.
if tokio::runtime::Handle::try_current().is_err() { if tokio::runtime::Handle::try_current().is_err() {
return; return;
} }
@ -166,14 +167,12 @@ impl CacheDB {
fn spawn_eager_init_thread(&self) { fn spawn_eager_init_thread(&self) {
let clone = self.clone(); let clone = self.clone();
// TODO(mmastrac): we should ensure tokio runtimes are consistently available or not debug_assert!(tokio::runtime::Handle::try_current().is_ok());
if tokio::runtime::Handle::try_current().is_ok() {
tokio::task::spawn_blocking(move || { tokio::task::spawn_blocking(move || {
let lock = clone.conn.lock(); let lock = clone.conn.lock();
clone.initialize(&lock); clone.initialize(&lock);
}); });
} }
}
/// Open the connection in memory or on disk. /// Open the connection in memory or on disk.
fn actually_open_connection( fn actually_open_connection(