From 8afd6bb8478f32e4d19bac0df2b102bbe6b06432 Mon Sep 17 00:00:00 2001 From: Henry Fontanier Date: Thu, 21 Nov 2024 17:20:03 +0100 Subject: [PATCH] fix: deadlock in notion getParents (#8813) Co-authored-by: Henry Fontanier --- connectors/src/connectors/notion/lib/parents.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/connectors/src/connectors/notion/lib/parents.ts b/connectors/src/connectors/notion/lib/parents.ts index e0273b13819c..6e317f4b857e 100644 --- a/connectors/src/connectors/notion/lib/parents.ts +++ b/connectors/src/connectors/notion/lib/parents.ts @@ -64,29 +64,29 @@ async function _getParents( return parents; case "page": case "database": { - if (seen.includes(pageOrDbId)) { + seen.push(pageOrDbId); + if (!pageOrDb.parentId) { logger.error( { connectorId, pageOrDbId, - seen, parentId: pageOrDb.parentId, }, - "getParents infinite loop" + "getParents parentId is undefined" ); - return parents.concat(seen); + throw new Error("getParent parentId is undefined"); } - seen.push(pageOrDbId); - if (!pageOrDb.parentId) { + if (seen.includes(pageOrDb.parentId)) { logger.error( { connectorId, pageOrDbId, + seen, parentId: pageOrDb.parentId, }, - "getParents parentId is undefined" + "getParents infinite loop" ); - throw new Error("getParent parentId is undefined"); + return parents.concat(seen); } if (onProgress) { await onProgress();