From 62b84a5fa870d36668df3ae09bf14d6d1da69d4f Mon Sep 17 00:00:00 2001 From: Fred Gruber Date: Sat, 6 Sep 2025 11:31:37 -0400 Subject: [PATCH 1/8] This commit fixes error when updating multiple confluence attachments Essentially, it uploads attachments one at a time instead of in parallel. Currently using a 0.8 second delay. --- src/publish/confluence/confluence.ts | 29 +++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/publish/confluence/confluence.ts b/src/publish/confluence/confluence.ts index 99233cac9b8..8ad69d6bc27 100644 --- a/src/publish/confluence/confluence.ts +++ b/src/publish/confluence/confluence.ts @@ -435,15 +435,26 @@ async function publish( LogPrefix.ATTACHMENT, ); - const uploadAttachmentsResult = await Promise.all( - uploadAttachments( - publishFiles.baseDir, - attachmentsToUpload, - toUpdate.id, - fileName, - existingAttachments, - ), - ); + const uploadAttachmentsResult: unknown[] = []; + + for (const att of attachmentsToUpload) { + // Start exactly ONE upload by calling the helper with a single attachment + const tasks = uploadAttachments( + publishFiles.baseDir, + [att], // <-- one at a time + toUpdate.id, + fileName, + existingAttachments, + ) as Promise[]; // uploadAttachments returns an array of Promises + + const res = await tasks[0]; + uploadAttachmentsResult.push(res); + + // short backoff (milliseconds) + const t0 = performance.now(); + await new Promise(r => setTimeout(r, 800)); // 0.8s + trace("[ATTACHMENT] sleptMs", { ms: Math.round(performance.now() - t0) }, LogPrefix.ATTACHMENT); + } trace( "uploadAttachmentsResult", uploadAttachmentsResult, From 253b726137be950471d703c2095b3557b49b0aea Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 18 Feb 2026 14:55:06 +0100 Subject: [PATCH 2/8] Fix indentation: convert tabs to spaces in attachment upload loop --- src/publish/confluence/confluence.ts | 40 ++++++++++++++-------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/publish/confluence/confluence.ts b/src/publish/confluence/confluence.ts index 8ad69d6bc27..3a80af25e79 100644 --- a/src/publish/confluence/confluence.ts +++ b/src/publish/confluence/confluence.ts @@ -435,26 +435,26 @@ async function publish( LogPrefix.ATTACHMENT, ); - const uploadAttachmentsResult: unknown[] = []; - - for (const att of attachmentsToUpload) { - // Start exactly ONE upload by calling the helper with a single attachment - const tasks = uploadAttachments( - publishFiles.baseDir, - [att], // <-- one at a time - toUpdate.id, - fileName, - existingAttachments, - ) as Promise[]; // uploadAttachments returns an array of Promises - - const res = await tasks[0]; - uploadAttachmentsResult.push(res); - - // short backoff (milliseconds) - const t0 = performance.now(); - await new Promise(r => setTimeout(r, 800)); // 0.8s - trace("[ATTACHMENT] sleptMs", { ms: Math.round(performance.now() - t0) }, LogPrefix.ATTACHMENT); - } + const uploadAttachmentsResult: unknown[] = []; + + for (const att of attachmentsToUpload) { + // Start exactly ONE upload by calling the helper with a single attachment + const tasks = uploadAttachments( + publishFiles.baseDir, + [att], // <-- one at a time + toUpdate.id, + fileName, + existingAttachments, + ) as Promise[]; // uploadAttachments returns an array of Promises + + const res = await tasks[0]; + uploadAttachmentsResult.push(res); + + // short backoff (milliseconds) + const t0 = performance.now(); + await new Promise(r => setTimeout(r, 800)); // 0.8s + trace("[ATTACHMENT] sleptMs", { ms: Math.round(performance.now() - t0) }, LogPrefix.ATTACHMENT); + } trace( "uploadAttachmentsResult", uploadAttachmentsResult, From dc884dee36831b7cd11ff7fef23305f16c7bd416 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 18 Feb 2026 14:56:24 +0100 Subject: [PATCH 3/8] Use existing sleep() helper instead of inline setTimeout --- src/publish/confluence/confluence.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/publish/confluence/confluence.ts b/src/publish/confluence/confluence.ts index 3a80af25e79..26c1c2dbf5f 100644 --- a/src/publish/confluence/confluence.ts +++ b/src/publish/confluence/confluence.ts @@ -450,9 +450,9 @@ async function publish( const res = await tasks[0]; uploadAttachmentsResult.push(res); - // short backoff (milliseconds) + // short backoff between uploads const t0 = performance.now(); - await new Promise(r => setTimeout(r, 800)); // 0.8s + await sleep(800); trace("[ATTACHMENT] sleptMs", { ms: Math.round(performance.now() - t0) }, LogPrefix.ATTACHMENT); } trace( From 1d3c4f2bc0c24b2133586252ff3dd523051d6bd9 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 18 Feb 2026 15:01:10 +0100 Subject: [PATCH 4/8] Extract attachment upload delay to named constant --- src/publish/confluence/confluence.ts | 3 ++- src/publish/confluence/constants.ts | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/publish/confluence/confluence.ts b/src/publish/confluence/confluence.ts index 26c1c2dbf5f..3aa8f04e74e 100644 --- a/src/publish/confluence/confluence.ts +++ b/src/publish/confluence/confluence.ts @@ -87,6 +87,7 @@ import { } from "./confluence-verify.ts"; import { DELETE_DISABLED, + ATTACHMENT_UPLOAD_DELAY_MS, DELETE_SLEEP_MILLIS, DESCENDANT_PAGE_SIZE, EXIT_ON_ERROR, @@ -452,7 +453,7 @@ async function publish( // short backoff between uploads const t0 = performance.now(); - await sleep(800); + await sleep(ATTACHMENT_UPLOAD_DELAY_MS); trace("[ATTACHMENT] sleptMs", { ms: Math.round(performance.now() - t0) }, LogPrefix.ATTACHMENT); } trace( diff --git a/src/publish/confluence/constants.ts b/src/publish/confluence/constants.ts index 7803856a629..533dff14644 100644 --- a/src/publish/confluence/constants.ts +++ b/src/publish/confluence/constants.ts @@ -18,6 +18,9 @@ export const V2EDITOR_METADATA = { export const DELETE_SLEEP_MILLIS = 1000; //TODO replace with polling +// Empirically determined delay to avoid Confluence 500 errors on concurrent attachment updates +export const ATTACHMENT_UPLOAD_DELAY_MS = 800; + export const CAN_SET_PERMISSIONS_DISABLED = "CONFLUENCE_LOCAL_STORAGE_CAN_SET_PERMISSIONS_DISABLED"; export const CAN_SET_PERMISSIONS_ENABLED_CACHED = "CONFLUENCE_LOCAL_STORAGE_CAN_SET_PERMISSIONS_ENABLED_CACHED" From dad03e71a76619a57240b59a2b77df0e2799b790 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 18 Feb 2026 16:17:03 +0100 Subject: [PATCH 5/8] Skip delay after last attachment upload --- src/publish/confluence/confluence.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/publish/confluence/confluence.ts b/src/publish/confluence/confluence.ts index 3aa8f04e74e..de464c8bb88 100644 --- a/src/publish/confluence/confluence.ts +++ b/src/publish/confluence/confluence.ts @@ -438,11 +438,11 @@ async function publish( const uploadAttachmentsResult: unknown[] = []; - for (const att of attachmentsToUpload) { + for (let i = 0; i < attachmentsToUpload.length; i++) { // Start exactly ONE upload by calling the helper with a single attachment const tasks = uploadAttachments( publishFiles.baseDir, - [att], // <-- one at a time + [attachmentsToUpload[i]], // <-- one at a time toUpdate.id, fileName, existingAttachments, @@ -451,10 +451,12 @@ async function publish( const res = await tasks[0]; uploadAttachmentsResult.push(res); - // short backoff between uploads - const t0 = performance.now(); - await sleep(ATTACHMENT_UPLOAD_DELAY_MS); - trace("[ATTACHMENT] sleptMs", { ms: Math.round(performance.now() - t0) }, LogPrefix.ATTACHMENT); + if (i < attachmentsToUpload.length - 1) { + // short backoff between uploads + const t0 = performance.now(); + await sleep(ATTACHMENT_UPLOAD_DELAY_MS); + trace("[ATTACHMENT] sleptMs", { ms: Math.round(performance.now() - t0) }, LogPrefix.ATTACHMENT); + } } trace( "uploadAttachmentsResult", From df55c93a7a233ece26aa3c5b2756e91df347ea05 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 18 Feb 2026 16:19:35 +0100 Subject: [PATCH 6/8] Preserve AttachmentSummary types instead of erasing to unknown --- src/publish/confluence/confluence.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/publish/confluence/confluence.ts b/src/publish/confluence/confluence.ts index de464c8bb88..1ed7600adbd 100644 --- a/src/publish/confluence/confluence.ts +++ b/src/publish/confluence/confluence.ts @@ -436,7 +436,7 @@ async function publish( LogPrefix.ATTACHMENT, ); - const uploadAttachmentsResult: unknown[] = []; + const uploadAttachmentsResult: (AttachmentSummary | null)[] = []; for (let i = 0; i < attachmentsToUpload.length; i++) { // Start exactly ONE upload by calling the helper with a single attachment @@ -446,7 +446,7 @@ async function publish( toUpdate.id, fileName, existingAttachments, - ) as Promise[]; // uploadAttachments returns an array of Promises + ); const res = await tasks[0]; uploadAttachmentsResult.push(res); From 1f38cc9ed1aac2260344209e427b4b8bd3ec5037 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 18 Feb 2026 16:20:56 +0100 Subject: [PATCH 7/8] Remove redundant sleep timing trace --- src/publish/confluence/confluence.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/publish/confluence/confluence.ts b/src/publish/confluence/confluence.ts index 1ed7600adbd..aa043431611 100644 --- a/src/publish/confluence/confluence.ts +++ b/src/publish/confluence/confluence.ts @@ -452,10 +452,7 @@ async function publish( uploadAttachmentsResult.push(res); if (i < attachmentsToUpload.length - 1) { - // short backoff between uploads - const t0 = performance.now(); await sleep(ATTACHMENT_UPLOAD_DELAY_MS); - trace("[ATTACHMENT] sleptMs", { ms: Math.round(performance.now() - t0) }, LogPrefix.ATTACHMENT); } } trace( From 9d7f46ee020e3b75513d507db258e902bd06c7e7 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 18 Feb 2026 17:39:17 +0100 Subject: [PATCH 8/8] Add changelog entry for Confluence attachment upload fix (#12558) --- news/changelog-1.9.md | 1 + 1 file changed, 1 insertion(+) diff --git a/news/changelog-1.9.md b/news/changelog-1.9.md index 1d2ed43075d..3de5e420900 100644 --- a/news/changelog-1.9.md +++ b/news/changelog-1.9.md @@ -135,6 +135,7 @@ All changes included in 1.9: ### Confluence +- ([#12558](https://github.com/quarto-dev/quarto-cli/issues/12558)): Fix 500 error when updating multiple Confluence attachments. Attachments are now uploaded sequentially instead of concurrently. (author: @fkgruber) - ([#13414](https://github.com/quarto-dev/quarto-cli/issues/13414)): Be more forgiving when Confluence server returns malformed JSON response. (author: @m1no) ### `gh-pages`