Skip to content

Commit 509d236

Browse files
authored
[CI] Workaround for Windows packaging tests hang on uploading artifacts (#137206) (#137438)
Calculate upload timeout based on file size. This change replaces the fixed 30-minute timeout with a calculated value, to avoid buildkite-agent on Windows hanging for 30 minutes for small files. (cherry picked from commit c527bbf)
1 parent 3d2a1b5 commit 509d236

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchBuildCompletePlugin.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.Arrays;
4545
import java.util.List;
4646
import java.util.Optional;
47+
import java.util.concurrent.TimeUnit;
4748

4849
import javax.inject.Inject;
4950

@@ -178,7 +179,11 @@ public void execute(BuildFinishedFlowAction.Parameters parameters) throws FileNo
178179
try {
179180
// we are very generious here, as the upload can take
180181
// a long time depending on its size
181-
pb.start().waitFor(30, java.util.concurrent.TimeUnit.MINUTES);
182+
long timeoutSec = calculateUploadWaitTimeoutSeconds(uploadFile);
183+
boolean completedInTime = pb.start().waitFor(timeoutSec, TimeUnit.SECONDS);
184+
if (completedInTime == false) {
185+
System.out.println("Timed out waiting for buildkite artifact upload after " + timeoutSec + " seconds");
186+
}
182187
} catch (InterruptedException e) {
183188
System.out.println("Failed to upload buildkite artifact " + e.getMessage());
184189
}
@@ -278,5 +283,14 @@ private static void createBuildArchiveTar(List<File> files, File projectDir, Fil
278283
private static String calculateArchivePath(Path path, Path projectPath) {
279284
return path.startsWith(projectPath) ? projectPath.relativize(path).toString() : path.getFileName().toString();
280285
}
286+
287+
private static long calculateUploadWaitTimeoutSeconds(File file) {
288+
long fileSizeBytes = file.length();
289+
long fileSizeMB = fileSizeBytes / (1024 * 1024);
290+
291+
// Allocate 4 seconds per MB (assumes ~250 KB/s upload speed)
292+
// with min 10 seconds and max 30 minutes
293+
return Math.max(10, Math.min(1800, fileSizeMB * 4));
294+
}
281295
}
282296
}

0 commit comments

Comments
 (0)