Skip to content

sqlite: Session methods crash after DatabaseSync is closed and reopened #64782

Description

@trivikr

Version

main

Platform

macOS 26.5.2

Subsystem

sqlite

What steps will reproduce the bug?

import { DatabaseSync } from 'node:sqlite';

const method = process.argv[2] ?? 'changeset';
const db = new DatabaseSync(':memory:');

db.exec('CREATE TABLE data (id INTEGER PRIMARY KEY)');
const session = db.createSession();

db.close();
db.open();

console.log(`calling session.${method}()`);
session[method]();
console.log('returned');

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

Always

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

Closing the database should invalidate associated session wrappers; after reopening, either method should throw an error such as Error: session is not open.

What do you see instead?

$ ../node/node repro.js changeset
calling session.changeset()
[1]    65858 segmentation fault  ../node/node repro.js changeset
$ ../node/node repro.js close
calling session.close()
[1]    66266 segmentation fault  ../node/node repro.js close

Both methods terminate the process because the session wrapper retains a stale native handle after db.close().

Additional information

No response

Metadata

Metadata

Assignees

Labels

sqliteIssues and PRs related to the SQLite subsystem.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions