Skip to content

cli/cmd/encore/daemon: open encore.db without the shared cache - #2631

Merged
jaglyserx merged 1 commit into
encoredev:mainfrom
gradientlabs-ai:encore-db-no-shared-cache
Nov 11, 2026
Merged

jaglyserx merged 1 commit into
encoredev:mainfrom
gradientlabs-ai:encore-db-no-shared-cache

Conversation

@twindebank

@twindebank twindebank commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The daemon opens encore.db with cache=shared. In shared-cache mode, SQLite does not wait for a lock held by another connection on the same cache. A second writer, or a write to a table another connection is reading, fails at once with database table is locked.

Apps upload a trace for every request, so requests that run at the same time write at the same time. The losing uploads fail, and the trace store logs the error and carries on. So under encore run, the local dashboard silently misses traces whenever requests overlap, and nothing outside the daemon's log shows it.

Fix

Drop cache=shared from the connection string. Each pooled connection then waits for the write lock, up to the driver's default busy timeout of 5 s, and WAL mode keeps reads running alongside writes.

The open-and-migrate step moves into openEncoreDB, so the test opens the database exactly as the daemon does. cache=shared dates from 2022, before WAL mode and immediate transactions were added.

Other fixes I tried against the same test:

Fix All uploads stored Why not
Drop cache=shared (this PR) Yes Each connection keeps its own page cache, a few MB more
Keep the shared cache, SetMaxOpenConns(1) Yes Reads queue behind every write, and a query inside a row loop would hang the daemon
Keep the shared cache, lock around trace writes No Reads and the trace cleaner still hit database table is locked
A second pool for traces only Yes Two pools on one file, and the rest of the daemon keeps the bug

Impact

TestEncoreDBStoresConcurrentTraceUploads makes 8 goroutines upload 50 traces each, the way concurrent requests do:

Complete spans stored, of 400
With cache=shared ~240 (234, 236, 238)
Without 400 (all three runs)

Tests

  • The new test fails on main (about 40% of spans lost) and passes with the fix.
  • go test -short -tags=dev_build ./cli/cmd/encore/daemon passes.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

The daemon opened encore.db with cache=shared. In shared-cache mode
SQLite fails a second writer, or a write to a table another connection
is reading, at once with "database table is locked" instead of waiting.
Apps upload a trace per request, so concurrent requests lost their traces:
a test of 400 concurrent uploads stores about 250 of them.

Without the shared cache each pooled connection waits up to the busy
timeout for the write lock, and WAL keeps reads running alongside writes.
All 400 uploads are stored. The open-and-migrate step moves into
openEncoreDB so the test opens the database as the daemon does.

@jaglyserx jaglyserx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great PR, removing cache mode for SQLite seems natural as the feature is discouraged in modern usage most of the time.

@jaglyserx
jaglyserx merged commit 0014ef4 into encoredev:main Nov 11, 2026
2 checks passed
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