Skip to content

Commit 4af38cd

Browse files
authored
Merge pull request #128 from useblacksmith/fix/export-timeout
fix: add timeout to buildx export operation
2 parents c213746 + e6eefa1 commit 4af38cd

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,30 @@ actionsToolkit.run(
248248
let exportRes;
249249
if (!buildError) {
250250
const buildxHistory = new BuildxHistory();
251-
exportRes = await buildxHistory.export({
252-
refs: ref ? [ref] : []
251+
252+
// Create a timeout promise that rejects after 30 seconds
253+
let timeoutId: NodeJS.Timeout | undefined;
254+
const exportTimeout = new Promise<never>((_, reject) => {
255+
timeoutId = setTimeout(() => reject(new Error('Export operation timed out after 30 seconds')), 30000);
253256
});
257+
258+
try {
259+
// Race between the export operation and the timeout
260+
exportRes = await Promise.race([
261+
buildxHistory.export({
262+
refs: ref ? [ref] : []
263+
}),
264+
exportTimeout
265+
]);
266+
// Clear the timeout if export completes successfully
267+
if (timeoutId) clearTimeout(timeoutId);
268+
} catch (exportError) {
269+
// Clear the timeout on error as well
270+
if (timeoutId) clearTimeout(timeoutId);
271+
// Log the error but continue with reporting
272+
core.warning(`Build export failed: ${(exportError as Error).message}`);
273+
core.info('Continuing with build reporting without export data');
274+
}
254275
}
255276

256277
if (buildId && isBlacksmithBuilder) {

0 commit comments

Comments
 (0)