Skip to content

Commit

Permalink
Merge pull request #77 from useblacksmith/fix-shutdown
Browse files Browse the repository at this point in the history
src: fix shutdown retry behavior
  • Loading branch information
adityamaru authored Dec 19, 2024
2 parents 726f2f6 + 1672d6f commit 31dd0cc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,16 +490,18 @@ export async function shutdownBuildkitd(): Promise<void> {
// Wait for buildkitd to shutdown with backoff retry
while (Date.now() - startTime < timeout) {
try {
const {stdout} = await execAsync('pgrep -f buildkitd');
if (!stdout.trim()) {
// Process not found, shutdown successful
await execAsync('pgrep -f buildkitd');
// Process still exists, wait and retry
await new Promise(resolve => setTimeout(resolve, backoff));
} catch (error) {
if (error.code === 1) {
// pgrep returns exit code 1 when no process is found, which means shutdown successful
core.debug('buildkitd successfully shutdown');
return;
}
} catch (error) {
// pgrep returns non-zero if process not found, which means shutdown successful
return;
// Some other error occurred
throw error;
}
await new Promise(resolve => setTimeout(resolve, backoff));
}

throw new Error('Timed out waiting for buildkitd to shutdown after 10 seconds');
Expand Down

0 comments on commit 31dd0cc

Please sign in to comment.