ssbc / ssb-db2

A new database for secure-scuttlebutt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash in ssb-db2 private when resuming compaction

staltz opened this issue · comments

Reproduction

  • ssb-db2 4.2.1
  • jitdb 7.0.2
  • async-append-only-log 4.3.6
  • Manyverse codebase

Reproduction steps:

  1. Delete some feeds
  2. Start compaction
  3. In the middle compaction, kill/crash the app
  4. Reopen the app
  5. Compaction resumes but the following crash happens

Screenshot from 2022-08-04 11-37-34

This is the line:

if (ciphertext.endsWith('.box')) {

And it was called from

const content = tryDecryptContent(ciphertext, recBuffer, pValue)

Which means it's reading from the canDecrypt index


Analysis

This means that the ciphertext is not a string. But the record is non-deleted because there is a check for non-null records.

So what I think this means is that the msg.value.content is an object, thus non-encrypted record. More guessing tells me that when the app re-opened, we allowed db2 queries to happen, and those might be using outdated offsets (because reindexing has not yet kicked in). And no db2 queries should happen at this point.

I think that the culprit is

ssb-db2/db.js

Line 104 in 44c4b04

const compacting = Obv().set(false)

because in this case the default value should be true, but because it's false then the queries are allowed to proceed:

ssb-db2/db.js

Lines 696 to 697 in 44c4b04

compacting,
(isCompacting) => isCompacting === false,

But it seems like we can just use the synchronous log.compactionProgress.value.done because it is synchronously defined by AAOL on startup:

https://github.com/ssbc/async-append-only-log/blob/2ad95069e94778b6d3cd62909b96c5da0b273fc2/index.js#L71-L75

Assume fixed by #381