From 2fb7d07207e727e6588a2d1b00c621b113b473ad Mon Sep 17 00:00:00 2001 From: marcus-pousette-hp Date: Tue, 26 May 2026 12:04:31 +0200 Subject: [PATCH] Fix pending update on peer close --- lib/replicator.js | 7 ++++++- test/replicate.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/replicator.js b/lib/replicator.js index e6cb1ad8..b8f8f3e4 100644 --- a/lib/replicator.js +++ b/lib/replicator.js @@ -2460,7 +2460,12 @@ module.exports = class Replicator { } this._onpeerupdate(false, peer) - if (inflight) this.updateAll() + if (inflight) { + this.updateAll() + } else { + this._checkUpgradeIfAvailable() + this._maybeResolveIfAvailableRanges() + } } _queueBlock(b) { diff --git a/test/replicate.js b/test/replicate.js index 9cdc933e..4bb412ed 100644 --- a/test/replicate.js +++ b/test/replicate.js @@ -956,6 +956,41 @@ test('findingPeers + done makes update return false if no peers', async function t.is(await u, false) }) +test('update wait resolves when unsynced peer closes without inflight', async function (t) { + t.plan(2) + + const a = await create(t) + const b = await create(t, a.key) + + let streams = null + let update = null + + const peerAdded = new Promise((resolve) => { + b.once('peer-add', () => { + update = b.update({ wait: true }) + + Promise.resolve().then(() => { + resolve(unreplicate(streams)) + }) + }) + }) + + streams = replicate(a, b, t, { teardown: false }) + + await peerAdded + + let timer = null + const timeout = new Promise((resolve) => { + timer = setTimeout(resolve, 250, null) + }) + + const result = await Promise.race([update, timeout]) + clearTimeout(timer) + + t.not(result, null, 'update resolved') + t.is(result, false, 'no upgrade was available') +}) + test.skip('can disable downloading from a peer', async function (t) { const a = await create(t)