summaryrefslogtreecommitdiff
path: root/cli/cache/cache_db.rs
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2023-03-28 14:06:57 -0600
committerGitHub <noreply@github.com>2023-03-28 14:06:57 -0600
commitc65149c0a072fa710098b14776c6cd3cc8a204d6 (patch)
tree7aafd51e926198a097a5ff93786800171db89bc6 /cli/cache/cache_db.rs
parent35fd8583efce33eaec4d88a26d96a5efb1690911 (diff)
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.
Diffstat (limited to 'cli/cache/cache_db.rs')
-rw-r--r--cli/cache/cache_db.rs17
1 files changed, 8 insertions, 9 deletions
diff --git a/cli/cache/cache_db.rs b/cli/cache/cache_db.rs
index 0f772091f..90840de1a 100644
--- a/cli/cache/cache_db.rs
+++ b/cli/cache/cache_db.rs
@@ -39,7 +39,7 @@ impl CacheDBConfiguration {
fn create_combined_sql(&self) -> String {
format!(
"
- PRAGMA journal_mode=OFF;
+ PRAGMA journal_mode=TRUNCATE;
PRAGMA synchronous=NORMAL;
PRAGMA temp_store=memory;
PRAGMA page_size=4096;
@@ -83,7 +83,8 @@ impl Drop for CacheDB {
_ => 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() {
return;
}
@@ -166,13 +167,11 @@ impl CacheDB {
fn spawn_eager_init_thread(&self) {
let clone = self.clone();
- // TODO(mmastrac): we should ensure tokio runtimes are consistently available or not
- if tokio::runtime::Handle::try_current().is_ok() {
- tokio::task::spawn_blocking(move || {
- let lock = clone.conn.lock();
- clone.initialize(&lock);
- });
- }
+ debug_assert!(tokio::runtime::Handle::try_current().is_ok());
+ tokio::task::spawn_blocking(move || {
+ let lock = clone.conn.lock();
+ clone.initialize(&lock);
+ });
}
/// Open the connection in memory or on disk.