TryGhost / node-sqlite3

SQLite3 bindings for Node.js
BSD 3-Clause "New" or "Revised" License
6.19k stars 813 forks source link

Sqlcipher makes sqlite unstable #1543

Open JeremyPasco opened 2 years ago

JeremyPasco commented 2 years ago

Hi, I've built sqlite with sqlcipher sucessfully. Everything works fine if I use sqlite without sqlcipher features. But as soon as I works with an encrypted db, the main process is killed after a few requests.

Here is an example thas works on a non-encrypted file but fails with a passphrase:

const db = new sqlite3.Database("my_file.db)
db.serialize(function () {

  // Do not work if the next line is used
  db.run("PRAGMA key = 'passphrase'", console.log)
  db.run(`CREATE TABLE IF NOT EXISTS demo (
    id INTEGER PRIMARY KEY,
    first_name TEXT,
    last_name TEXT
  )`, console.log)

  db.run("INSERT INTO demo (id, first_name, last_name) VALUES (1, 'a', 'b')", console.log)

  db.all("select * from demo", (err, rows) => console.log(rows))
})

db.close()

In both cases (with or without encryption), I get correct results in console. But with encryption the main process crashes with the following message just after the requests return: App • ⚠️ Electron process was killed. Exiting...

Puting the whole script in a try-catch doesn't help. Sometimes the main process stay alive for a few seconds, but calling db.close() or any sql exception (ie: duplicate key) seem to crash the process instantly.

Am I missing something to deal with encryption properly?

mduclehcm commented 2 years ago

I got the same issue on electron 7.3.2

mduclehcm commented 2 years ago

Browser window crashed with invalid bytecode error. (printed to main process std) image