mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
Run SQLite backup after-work callbacks inside an internal callback scope. This drains promise reactions and next ticks before the event loop can become idle. Add a child-process regression test where backup is the final active request. Assisted-by: Codex Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: https://github.com/nodejs/node/pull/65666 Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Richard Lau <richard.lau@ibm.com>
35 lines
772 B
JavaScript
35 lines
772 B
JavaScript
import { backup, DatabaseSync } from 'node:sqlite';
|
|
|
|
const source = new DatabaseSync(':memory:');
|
|
source.exec(`
|
|
CREATE TABLE data(value);
|
|
INSERT INTO data VALUES (zeroblob(1048576));
|
|
`);
|
|
|
|
let keepAlive = setInterval(() => {}, 1_000);
|
|
let settled = false;
|
|
|
|
process.once('beforeExit', () => {
|
|
if (!settled) {
|
|
process.stderr.write('backup promise did not settle before the event loop became idle\n');
|
|
process.exit(1);
|
|
}
|
|
});
|
|
|
|
backup(source, process.argv[2], {
|
|
rate: 1,
|
|
progress() {
|
|
if (keepAlive !== undefined) {
|
|
clearInterval(keepAlive);
|
|
keepAlive = undefined;
|
|
}
|
|
},
|
|
}).then(() => {
|
|
settled = true;
|
|
source.close();
|
|
}, (error) => {
|
|
settled = true;
|
|
process.stderr.write(`${error.stack ?? error}\n`);
|
|
process.exitCode = 1;
|
|
});
|