From 03fb47f9c876f1c6f86549a2aff5a0dd5d83a0f1 Mon Sep 17 00:00:00 2001 From: taea Date: Thu, 9 Jul 2026 12:42:19 -0400 Subject: [PATCH] Improve timeout handling in IPFSBlockStorage methods --- src/storage/ipfs-block.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/storage/ipfs-block.js b/src/storage/ipfs-block.js index a1c4acca..ef8c8aa3 100644 --- a/src/storage/ipfs-block.js +++ b/src/storage/ipfs-block.js @@ -38,8 +38,12 @@ const IPFSBlockStorage = async ({ ipfs, pin, timeout } = {}) => { */ const put = async (hash, data) => { const cid = CID.parse(hash, base58btc) - const { signal } = new TimeoutController(timeout || DefaultTimeout) - await ipfs.blockstore.put(cid, data, { signal }) + const timeoutController = new TimeoutController(timeout || DefaultTimeout) + try { + await ipfs.blockstore.put(cid, data, { signal: timeoutController.signal }) + } finally { + timeoutController.clear() + } if (pin && !(await ipfs.pins.isPinned(cid))) { await drain(ipfs.pins.add(cid)) @@ -58,10 +62,14 @@ const IPFSBlockStorage = async ({ ipfs, pin, timeout } = {}) => { */ const get = async (hash) => { const cid = CID.parse(hash, base58btc) - const { signal } = new TimeoutController(timeout || DefaultTimeout) - const block = await ipfs.blockstore.get(cid, { signal }) - if (block) { - return block + const timeoutController = new TimeoutController(timeout || DefaultTimeout) + try { + const block = await ipfs.blockstore.get(cid, { signal: timeoutController.signal }) + if (block) { + return block + } + } finally { + timeoutController.clear() } }