Repository navigation
Description
Summary
On Linux, the bb server process holds no lasting POSIX lock on its main database's shared-memory file (bb.db-shm), while it does hold one on every plugin database it has open. Without that lock, any second process that opens bb.db (even read-only) can reset the wal-index while the server has it mapped, and the server dies with SIGBUS. This crashed our server 35 times in one evening.
Environment
- bb-app 0.45.0, Linux x86_64 (Ubuntu, kernel 6.8), Node 24.18.0 (bundled SQLite 3.53.1), ext4.
bb.dbis 11.6 GB with a 440 MB WAL.
What we see
/proc/locks, sampled 16 times over 8 seconds, for the server pid:
plugins/firstmate/data.db-shm: one lasting lock in every sample:POSIX ADVISORY READ <server pid> <dev:inode> 128 128(SQLite's "database in use" byte).bb.db-shm: no lock in 13 samples and one short-lived lock in 3 samples. Never the lasting lock at byte 128.bb.dbandbb.db-wal: none.
A full server restart does not change this: the state is the same within 30 seconds of start. So it is not a lost lock after long uptime.
A likely cause, not proven: something in the server process opens and closes a second file descriptor on bb.db-shm (or bb.db) after SQLite has taken its locks. On POSIX, closing any descriptor for a file drops all of that process's locks on it.
Consequence
A plugin host worker opened bb.db with node:sqlite DatabaseSync(path, { readOnly: true }), ran one query and closed it. With no lock visible, SQLite in that process treated the wal-index as unused, reset it and regrew it in 4096-byte steps. The server still had the 32768-byte file mapped:
--- SIGBUS {si_signo=SIGBUS, si_code=BUS_ADRERR, si_addr=0x73030f0d62de} ---
+++ killed by SIGBUS (core dumped) +++
The fault address was inside the mapping of bb.db-shm (offset 25310, file seen at 20480 bytes during the outside access). systemd reported status=128 from the wrapper. Because the plugin read the database on every server start, the server looped: 30 restarts in 14 minutes.
On a throwaway WAL database with two processes: a writer that holds its locks survived 423 outside reads; a writer whose locks had been dropped died with SIGBUS on the first outside read.
We have removed the direct read from the plugin. The server is still exposed to any other process that opens the file (a sqlite3 shell, a backup tool, another plugin).
Expected
The server keeps SQLite's locks on bb.db-shm for as long as it has the database open, as it does for plugin databases, so a second reader cannot reset the wal-index under it.
Related, smaller
The server log shows a "Slow DB query" on terminal_sessions (about 100-150 ms) 20 to 30 times a minute. Its duration did not change when open terminals went from 45 to 0.
Activity
Move archived threads to cold storage from Storage & retention, with …