From 44cdf7b6c9004e14643870aeedb7b8a481013203 Mon Sep 17 00:00:00 2001 From: Hans Klunder Date: Tue, 30 Sep 2025 20:20:08 +0000 Subject: [PATCH 1/2] fix: fix outgoingStream when no value is present for a key --- asyncPersistence.js | 5 ++++- test/own.js | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/asyncPersistence.js b/asyncPersistence.js index 64da800..4af8549 100644 --- a/asyncPersistence.js +++ b/asyncPersistence.js @@ -511,7 +511,10 @@ class AsyncRedisPersistence { async function * lrangeResult () { for (const key of await db.lrange(clientListKey, 0, maxSessionDelivery)) { - yield getDecodedValue(db, clientListKey, key) + const decoded = await getDecodedValue(db, clientListKey, key) + if (decoded !== undefined) { + yield decoded + } } } diff --git a/test/own.js b/test/own.js index 89d3a08..57b6b13 100644 --- a/test/own.js +++ b/test/own.js @@ -229,5 +229,29 @@ async function doTest () { t.assert.equal(wills.length, 1, 'should only be one will') cleanUpPersistence(t, p) }) + + test('lrange delivers key with no value', async t => { + t.plan(1) + await cleanDB() + + const Redis = require('ioredis') + const db = new Redis() + await once(db, 'connect') + const clientId = 'ghostClient' + const listKey = 'outgoing:' + encodeURIComponent(clientId) + // we just add a key to the list with no associated packet + await db.rpush(listKey, 'ghostKey') + + const p = await setUpPersistence(t, 'ghost', { conn: db }) + const instance = p.instance + const packets = [] + for await (const pkt of instance.outgoingStream({ id: clientId })) { + packets.push(pkt) + } + t.assert.equal(packets.length, 0, 'no packets should be delivered') + await db.del(listKey) + cleanUpPersistence(t, p) + db.disconnect() + }) } doTest() From 1851afe8f350638f2624a731ae343002fc2116f7 Mon Sep 17 00:00:00 2001 From: Hans Klunder Date: Wed, 1 Oct 2025 05:50:46 +0000 Subject: [PATCH 2/2] fix undefined result in createWillStream --- asyncPersistence.js | 2 +- test/own.js | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/asyncPersistence.js b/asyncPersistence.js index 4af8549..e170475 100644 --- a/asyncPersistence.js +++ b/asyncPersistence.js @@ -111,7 +111,7 @@ async function getRetainedValue (db, topic, hasClusters) { async function * createWillStream (db, brokers, maxWills) { for (const key of await db.lrange(WILLSKEY, 0, maxWills)) { const result = await getDecodedValue(db, WILLSKEY, key) - if (!brokers || !brokers[key.split(':')[1]]) { + if ((result !== undefined) && (!brokers || !brokers[key.split(':')[1]])) { yield result } } diff --git a/test/own.js b/test/own.js index 57b6b13..86e2def 100644 --- a/test/own.js +++ b/test/own.js @@ -233,10 +233,7 @@ async function doTest () { test('lrange delivers key with no value', async t => { t.plan(1) await cleanDB() - - const Redis = require('ioredis') - const db = new Redis() - await once(db, 'connect') + const db = await createDB() const clientId = 'ghostClient' const listKey = 'outgoing:' + encodeURIComponent(clientId) // we just add a key to the list with no associated packet @@ -251,7 +248,23 @@ async function doTest () { t.assert.equal(packets.length, 0, 'no packets should be delivered') await db.del(listKey) cleanUpPersistence(t, p) - db.disconnect() + }) + + test('createWillStream delivers key with no value', async t => { + t.plan(1) + await cleanDB() + const db = await createDB() + await db.rpush('will', 'ghostWillKey') + + const p = await setUpPersistence(t, 'ghostWill', { conn: db }) + const instance = p.instance + const wills = [] + for await (const will of instance.streamWill()) { + wills.push(will) + } + t.assert.equal(wills.length, 0, 'geen wills gevonden als value ontbreekt') + await db.del('will') + cleanUpPersistence(t, p) }) } doTest()