Skip to content

Commit

Permalink
Merge pull request #69 from useblacksmith/umount-timeout
Browse files Browse the repository at this point in the history
src: make post unmount even if buildkitd is no longer present
  • Loading branch information
adityamaru authored Dec 11, 2024
2 parents c6b6f32 + de0451e commit 5b9a178
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 34 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.

66 changes: 34 additions & 32 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,17 +318,17 @@ actionsToolkit.run(
}
await shutdownBuildkitd();
core.info('Shutdown buildkitd');
for (let attempt = 1; attempt <= 3; attempt++) {
for (let attempt = 1; attempt <= 10; attempt++) {
try {
await execAsync(`sudo umount ${mountPoint}`);
core.debug(`${mountPoint} has been unmounted`);
break;
} catch (error) {
if (attempt === 3) {
if (attempt === 10) {
throw error;
}
core.warning(`Unmount failed, retrying (${attempt}/3)...`);
await new Promise(resolve => setTimeout(resolve, 100));
core.warning(`Unmount failed, retrying (${attempt}/10)...`);
await new Promise(resolve => setTimeout(resolve, 300));
}
}
core.info('Unmounted device');
Expand Down Expand Up @@ -363,42 +363,44 @@ actionsToolkit.run(
fs.rmSync(stateHelper.tmpDir, {recursive: true});
});
}
// Check for any lingering buildkitd processes as a safeguard.
// TODO(adityamaru): Let's add an endpoint to sentry alert on this cause this
// means we've not handled some error throws in the main action.
// Check for any lingering buildkitd processes and try to clean up mounts
try {
const {stdout} = await execAsync('pgrep buildkitd');
if (stdout) {
core.info('Found lingering buildkitd processes, cleaning up...');
await shutdownBuildkitd();
core.info('Shutdown buildkitd');
// Check for buildkitd processes first
try {
const {stdout} = await execAsync('pgrep buildkitd');
if (stdout) {
core.info('Found lingering buildkitd processes, cleaning up...');
await shutdownBuildkitd();
core.info('Shutdown buildkitd');
}
} catch (error) {
// pgrep returns non-zero if no processes found, which is fine
core.debug('No lingering buildkitd processes found');
}

// Try to unmount if mounted
try {
const {stdout: mountOutput} = await execAsync(`mount | grep ${mountPoint}`);
if (mountOutput) {
for (let attempt = 1; attempt <= 3; attempt++) {
try {
await execAsync(`sudo umount ${mountPoint}`);
core.debug(`${mountPoint} has been unmounted`);
break;
} catch (error) {
if (attempt === 3) {
throw error;
}
core.warning(`Unmount failed, retrying (${attempt}/3)...`);
await new Promise(resolve => setTimeout(resolve, 100));
try {
const {stdout: mountOutput} = await execAsync(`mount | grep ${mountPoint}`);
if (mountOutput) {
for (let attempt = 1; attempt <= 3; attempt++) {
try {
await execAsync(`sudo umount ${mountPoint}`);
core.debug(`${mountPoint} has been unmounted`);
break;
} catch (error) {
if (attempt === 3) {
throw error;
}
core.warning(`Unmount failed, retrying (${attempt}/3)...`);
await new Promise(resolve => setTimeout(resolve, 100));
}
core.info('Unmounted device');
}
} catch (error) {
core.warning(`Error during cleanup: ${error.message}`);
core.info('Unmounted device');
}
} catch (error) {
core.warning(`Error during cleanup: ${error.message}`);
}
} catch (error) {
// pgrep returns non-zero if no processes found, which is fine.
core.debug('No lingering buildkitd processes found');
core.warning(`Error during final cleanup: ${error.message}`);
}
}
);
Expand Down

0 comments on commit 5b9a178

Please sign in to comment.