Skip to content

sqlite: prepare().run() silently fails or drops data with INSERT OR REPLACE inside a synchronous loop #63998

@realBoBao

Description

@realBoBao

Version

v24.10.0

Platform

Microsoft Windows NT 10.0.26200.0
x64

Subsystem

sqlite

What steps will reproduce the bug?

import { DatabaseSync } from 'node:sqlite';

// Create an in-memory database for clean testing
const db = new DatabaseSync(':memory:');
db.exec(CREATE TABLE IF NOT EXISTS vectors ( id TEXT PRIMARY KEY, text TEXT ));

const insertStmt = db.prepare('INSERT OR REPLACE INTO vectors (id, text) VALUES (?, ?)');

// Execute the statement inside a synchronous loop
for (let i = 0; i < 100; i++) {
insertStmt.run(id_${i}, sample_text_${i});
}

// Verify the data insertion
const rowCount = db.prepare('SELECT COUNT(*) as count FROM vectors').get().count;
console.log('Expected rows: 100');
console.log('Actual rows:', rowCount);

How often does it reproduce? Is there a required condition?

100% reproducible on Node v24.10.0 when using a loop with INSERT OR REPLACE.

What is the expected behavior? Why is that the expected behavior?

The database should contain all 100 records inserted within the loop. The statement.run() should either successfully persist the data or throw a clear JavaScript exception if the operation fails. Silent failures lead to severe data loss in production.

What do you see instead?

The loop executes completely without throwing any exceptions, but the records are silently dropped. The final COUNT(*) query returns 0 (or a number significantly lower than the loop count), indicating that the underlying SQLite driver ignored the operations without notifying the JS runtime.

Additional information

I am sorry I put it on AI so it was public like linus said

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs more infoIssues without a valid reproduction.sqliteIssues and PRs related to the SQLite subsystem.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions