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` diff --git a/src/publish/confluence/confluence.ts b/src/publish/confluence/confluence.ts index 99233cac9b8..aa043431611 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, @@ -435,15 +436,25 @@ async function publish( LogPrefix.ATTACHMENT, ); - const uploadAttachmentsResult = await Promise.all( - uploadAttachments( + const uploadAttachmentsResult: (AttachmentSummary | null)[] = []; + + 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, - attachmentsToUpload, + [attachmentsToUpload[i]], // <-- one at a time toUpdate.id, fileName, existingAttachments, - ), - ); + ); + + const res = await tasks[0]; + uploadAttachmentsResult.push(res); + + if (i < attachmentsToUpload.length - 1) { + await sleep(ATTACHMENT_UPLOAD_DELAY_MS); + } + } trace( "uploadAttachmentsResult", uploadAttachmentsResult, 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"