Skip to content

Commit abc5b90

Browse files
fix awaiting locks
1 parent 7330c51 commit abc5b90

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

cpp/ConnectionState.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ void ConnectionState::doWork() {
9292
++threadBusy;
9393
task(connection);
9494
--threadBusy;
95+
// Need to notify in order for waitFinished to be updated when
96+
// the queue is empty and not busy
97+
workQueueConditionVariable.notify_all();
9598
}
96-
workQueueConditionVariable.notify_all();
9799
}
98100

99101
void ConnectionState::waitFinished() {

tests/tests/sqlite/rawQueries.spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,24 @@ export function registerBaseTests() {
183183
expect(res.rows?._array).to.eql([]);
184184
});
185185

186+
/**
187+
* The lock manager will attempt to free the connection lock
188+
* as soon as the callback resolves, but it should also
189+
* correctly await any queued work such as tx.rollback();
190+
*/
191+
it('Transaction, manual rollback, forgot await', async () => {
192+
const { id, name, age, networth } = generateUserInfo();
193+
194+
await db.writeTransaction(async (tx) => {
195+
await tx.execute('INSERT INTO "User" (id, name, age, networth) VALUES(?, ?, ?, ?)', [id, name, age, networth]);
196+
// Purposely forget await this.
197+
tx.rollback();
198+
});
199+
200+
const res = await db.execute('SELECT * FROM User');
201+
expect(res.rows?._array).to.eql([]);
202+
});
203+
186204
it('Transaction, executed in order', async () => {
187205
// ARRANGE: Setup for multiple transactions
188206
const iterations = 10;

0 commit comments

Comments
 (0)