@fungi.computer/watchdog 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/node-sqlite.js +24 -2
- package/package.json +1 -1
package/dist/node-sqlite.js
CHANGED
|
@@ -47,6 +47,11 @@ export function fromNodeSqlite(database) {
|
|
|
47
47
|
},
|
|
48
48
|
transactionSync: (operation) => {
|
|
49
49
|
const name = `watchdog_owner_${String(transaction++)}`;
|
|
50
|
+
// The outermost savepoint opens the real transaction, so its RELEASE is
|
|
51
|
+
// the commit, and SQLite refuses a commit as busy while another
|
|
52
|
+
// connection reads. A refused commit leaves the transaction open.
|
|
53
|
+
const inTransaction = () => database.isTransaction;
|
|
54
|
+
const outermost = !inTransaction();
|
|
50
55
|
database.exec(`SAVEPOINT ${name}`);
|
|
51
56
|
try {
|
|
52
57
|
const result = operation();
|
|
@@ -54,8 +59,25 @@ export function fromNodeSqlite(database) {
|
|
|
54
59
|
return result;
|
|
55
60
|
}
|
|
56
61
|
catch (cause) {
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
if (!outermost) {
|
|
63
|
+
// Inside the caller's transaction a RELEASE never commits.
|
|
64
|
+
database.exec(`ROLLBACK TO ${name}`);
|
|
65
|
+
database.exec(`RELEASE ${name}`);
|
|
66
|
+
throw cause;
|
|
67
|
+
}
|
|
68
|
+
// A plain ROLLBACK needs no exclusive lock, so it succeeds exactly
|
|
69
|
+
// when the commit could not: the connection never stays in the
|
|
70
|
+
// transaction, holding its lock against every other connection.
|
|
71
|
+
// Some failures (OR ROLLBACK, disk full) end the transaction in
|
|
72
|
+
// SQLite itself; then there is nothing to roll back and the caller
|
|
73
|
+
// sees the original error.
|
|
74
|
+
try {
|
|
75
|
+
if (inTransaction())
|
|
76
|
+
database.exec("ROLLBACK");
|
|
77
|
+
}
|
|
78
|
+
catch (rollbackCause) {
|
|
79
|
+
throw new AggregateError([cause, rollbackCause], "SQLite transaction failed and could not be rolled back", { cause: rollbackCause });
|
|
80
|
+
}
|
|
59
81
|
throw cause;
|
|
60
82
|
}
|
|
61
83
|
},
|