import { Database } from "https://deno.land/x/sqlite3@0.7.1/mod.ts";
const db = new Database(":memory:");
db.exec(`
CREATE TABLE foo (
id INTEGER NOT NULL
);
`);
const s = db.prepare("INSERT INTO foo (id) VALUES (?)");
for (let i = 0; i < 1000000; i++) {
s.run(i);
}
db.close();
const a: number[] = [];
for (let i = 0; i < 1000000; i++) {
a.push(i);
}
console.log(a.reduce((s, v) => s + v, 0));
I actually don't know why it happens, but feels finalizer related. The random array code chunk at the end is important as it creates pressure on the GC.
I've noticed the lib started to segfault after version 0.6.1 somewhere. My guess is that it's due to finalization code here: https://github.com/denodrivers/sqlite3/blob/a1c7e4d276ae48e6aae1282a47c8e2d523af79c5/src/database.ts#L652-L657 Because it doesn't unregister global finalizers as it does here: https://github.com/denodrivers/sqlite3/blob/a1c7e4d276ae48e6aae1282a47c8e2d523af79c5/src/statement.ts#L649-L655
A rough code sample that causes it:
I actually don't know why it happens, but feels finalizer related. The random array code chunk at the end is important as it creates pressure on the GC.
Most likely "double free" happens somewhere.
Can somebody reproduce it?