Skip to content

Commit 781138a

Browse files
committed
Fix race condition by setting download status early in S3 and Swift post-download handling
1 parent 6b10fe4 commit 781138a

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

core/src/main/java/com/cloud/storage/template/S3TemplateDownloader.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ public void progressChanged(ProgressEvent progressEvent) {
215215
try {
216216
// Wait for the upload to complete.
217217
upload.waitForCompletion();
218+
// Set status directly to avoid race condition.
219+
status = Status.DOWNLOAD_FINISHED;
218220
} catch (InterruptedException e) {
219221
errorString = "Interruption occurred while waiting for upload of " + downloadUrl + " to complete";
220222
logger.warn(errorString);

services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/template/DownloadManagerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ public void setDownloadStatus(String jobId, Status status) {
316316
// For S3 and Swift, which are considered "remote",
317317
// as in the file cannot be accessed locally,
318318
// we run the postRemoteDownload() method.
319+
// Set early so status polls see DOWNLOADED; overridden on error below
320+
td.setStatus(Status.POST_DOWNLOAD_FINISHED);
319321
td.setDownloadError("Download success, starting install ");
320322
String result = postRemoteDownload(jobId);
321323
if (result != null) {
@@ -324,7 +326,6 @@ public void setDownloadStatus(String jobId, Status status) {
324326
td.setDownloadError("Failed post download install: " + result);
325327
((S3TemplateDownloader) td).cleanupAfterError();
326328
} else {
327-
td.setStatus(Status.POST_DOWNLOAD_FINISHED);
328329
td.setDownloadError("Install completed successfully at " + new SimpleDateFormat().format(new Date()));
329330
}
330331
} else {

0 commit comments

Comments
 (0)