From b539877a3977d9f687bc7e14b49ee9f4c5582b11 Mon Sep 17 00:00:00 2001 From: haad Date: Tue, 20 May 2025 10:09:35 +0300 Subject: [PATCH] Fix race conditions upon dropping database --- src/database.js | 2 +- src/oplog/log.js | 4 ++++ test/databases/replication/keyvalue-indexed.test.js | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/database.js b/src/database.js index 0885d24..6c84ef3 100644 --- a/src/database.js +++ b/src/database.js @@ -183,7 +183,7 @@ const Database = async ({ ipfs, identity, address, name, access, directory, meta * @async */ const drop = async () => { - await queue.onIdle() + await queue.clear() await log.clear() if (access && access.drop) { await access.drop() diff --git a/src/oplog/log.js b/src/oplog/log.js index e006ebf..0bddde6 100644 --- a/src/oplog/log.js +++ b/src/oplog/log.js @@ -488,6 +488,8 @@ const Log = async (identity, { logId, logHeads, access, entryStorage, headsStora * @instance */ const clear = async () => { + await appendQueue.clear() + await joinQueue.clear() await oplogStore.clear() } @@ -497,6 +499,8 @@ const Log = async (identity, { logId, logHeads, access, entryStorage, headsStora * @instance */ const close = async () => { + await appendQueue.onIdle() + await joinQueue.onIdle() await oplogStore.close() } diff --git a/test/databases/replication/keyvalue-indexed.test.js b/test/databases/replication/keyvalue-indexed.test.js index 7c88017..9d193be 100644 --- a/test/databases/replication/keyvalue-indexed.test.js +++ b/test/databases/replication/keyvalue-indexed.test.js @@ -319,7 +319,8 @@ describe('KeyValueIndexed Database Replication', function () { ]) }) - it.only('indexes deletes correctly', async () => { + it('indexes deletes correctly', async () => { + const databaseId = 'kv-CCC' let replicated = false let err