mirror of
https://github.com/docker/setup-buildx-action.git
synced 2025-05-09 07:59:31 +02:00
Add timeout control to prevent long waits during buildkit initialization
Signed-off-by: Daniel Amar <daniel.amar@onepeloton.com>
This commit is contained in:
parent
bc3c5abd64
commit
66d7daabf8
1 changed files with 23 additions and 7 deletions
30
src/main.ts
30
src/main.ts
|
@ -209,19 +209,35 @@ actionsToolkit.run(
|
||||||
try {
|
try {
|
||||||
await retryWithBackoff(
|
await retryWithBackoff(
|
||||||
async () => {
|
async () => {
|
||||||
const res = await Exec.getExecOutput(inspectCmd.command, inspectCmd.args, {
|
// Create a promise that will timeout after 15 seconds
|
||||||
ignoreReturnCode: true
|
const timeoutPromise = new Promise<never>((_, reject) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
reject(new Error('Timeout exceeded while waiting for buildkit to initialize'));
|
||||||
|
}, 15000); // 15 second timeout
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
// Create the actual command execution promise
|
||||||
throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error');
|
const execPromise = Exec.getExecOutput(inspectCmd.command, inspectCmd.args, {
|
||||||
}
|
ignoreReturnCode: true
|
||||||
return res;
|
}).then(res => {
|
||||||
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
|
throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error');
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Race the timeout against the actual command
|
||||||
|
// If the command takes too long, we'll get the timeout error instead
|
||||||
|
return Promise.race([execPromise, timeoutPromise]);
|
||||||
},
|
},
|
||||||
5, // maxRetries - retry up to 5 times for buildkit initialization
|
5, // maxRetries - retry up to 5 times for buildkit initialization
|
||||||
1000, // initialDelay - start with 1 second
|
1000, // initialDelay - start with 1 second
|
||||||
15000, // maxDelay - cap at 15 seconds
|
15000, // maxDelay - cap at 15 seconds
|
||||||
isBuildkitSocketError // only retry on buildkit socket errors
|
(error) => {
|
||||||
|
// Retry on buildkit socket errors or timeouts
|
||||||
|
return isBuildkitSocketError(error) ||
|
||||||
|
error.message.includes('Timeout exceeded while waiting for buildkit');
|
||||||
|
}
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Log the warning but continue - this matches current behavior where builds still succeed
|
// Log the warning but continue - this matches current behavior where builds still succeed
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue