Skip to content

Commit 66d7daa

Browse files
Add timeout control to prevent long waits during buildkit initialization
Signed-off-by: Daniel Amar <[email protected]>
1 parent bc3c5ab commit 66d7daa

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/main.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,35 @@ actionsToolkit.run(
209209
try {
210210
await retryWithBackoff(
211211
async () => {
212-
const res = await Exec.getExecOutput(inspectCmd.command, inspectCmd.args, {
212+
// Create a promise that will timeout after 15 seconds
213+
const timeoutPromise = new Promise<never>((_, reject) => {
214+
setTimeout(() => {
215+
reject(new Error('Timeout exceeded while waiting for buildkit to initialize'));
216+
}, 15000); // 15 second timeout
217+
});
218+
219+
// Create the actual command execution promise
220+
const execPromise = Exec.getExecOutput(inspectCmd.command, inspectCmd.args, {
213221
ignoreReturnCode: true
222+
}).then(res => {
223+
if (res.stderr.length > 0 && res.exitCode != 0) {
224+
throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error');
225+
}
226+
return res;
214227
});
215228

216-
if (res.stderr.length > 0 && res.exitCode != 0) {
217-
throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error');
218-
}
219-
return res;
229+
// Race the timeout against the actual command
230+
// If the command takes too long, we'll get the timeout error instead
231+
return Promise.race([execPromise, timeoutPromise]);
220232
},
221233
5, // maxRetries - retry up to 5 times for buildkit initialization
222234
1000, // initialDelay - start with 1 second
223235
15000, // maxDelay - cap at 15 seconds
224-
isBuildkitSocketError // only retry on buildkit socket errors
236+
(error) => {
237+
// Retry on buildkit socket errors or timeouts
238+
return isBuildkitSocketError(error) ||
239+
error.message.includes('Timeout exceeded while waiting for buildkit');
240+
}
225241
);
226242
} catch (error) {
227243
// Log the warning but continue - this matches current behavior where builds still succeed

0 commit comments

Comments
 (0)