Skip to content

Conversation

@Karavil
Copy link
Contributor

@Karavil Karavil commented Dec 8, 2025

Summary

Adds --litestream-busy-timeout option to configure SQLite's busy_timeout for litestream's database connection. Value is a duration string (e.g. "5s", "30s", "1m").

Default is "1s", which we believe is litestream's internal default (see litestream db.go NewDB - BusyTimeout: 1 * time.Second).

Motivation

We've been experiencing "database is locked" errors during heavy write operations. There's a comment in Zero's codebase that suggests this could cause deadlocks:

// packages/zero-cache/src/db/wal-checkpoint.test.ts (lines 83-85)
// With a BEGIN CONCURRENT, the checkpoint fails. Note that if this were
// litestream, this would result in a deadlock as litestream does not
// set a busy_timeout.

However, we found that litestream's source code shows a default BusyTimeout of 1 second. We'd appreciate clarification from the Zero team on whether this comment is still accurate or if something else is happening.

Change

  • Adds busyTimeout config option (default "1s")
  • Passes ZERO_LITESTREAM_BUSY_TIMEOUT env var to litestream
  • Adds busy-timeout line to config.yml

Since we're setting the default to what we believe is litestream's internal default (1s), this should preserve existing behavior while allowing operators to tune it higher if needed.

Usage

# Increase busy timeout to 30 seconds
zero-cache --litestream-busy-timeout=30s

Questions for Zero Team

  1. Is the comment in wal-checkpoint.test.ts still accurate? Does litestream actually not set a busy_timeout in Zero's setup?
  2. If litestream's default is 1s, what explains the deadlock behavior we're seeing?
  3. Is there a reason busy-timeout wasn't explicitly set in config.yml before?

@vercel
Copy link

vercel bot commented Dec 8, 2025

@Karavil is attempting to deploy a commit to the Rocicorp Team on Vercel.

A member of the Team first needs to authorize it.

@Karavil Karavil force-pushed the feat/litestream-busy-timeout branch from 702230c to ccc339c Compare December 8, 2025 20:39
Adds --litestream-busy-timeout option to configure SQLite's busy_timeout
for litestream's database connection. Value is a duration string (e.g.
"5s", "30s", "1m").

Default is "1s" (litestream's default), preserving existing behavior.
Setting a higher value may help prevent checkpoint failures during
heavy write operations where the replicator holds the write lock for
extended periods.
@Karavil Karavil force-pushed the feat/litestream-busy-timeout branch from ccc339c to 83334b4 Compare December 8, 2025 20:43
Copy link
Contributor

@darkgnotic darkgnotic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Karavil !

Can you please run npm run test -- -u to update the test snapshots?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants