Skip to content

Commit fbdeee8

Browse files
refactor: use shell timeout command for flush operation
Co-Authored-By: maru@blacksmith.sh <adityamaru@gmail.com>
1 parent 735bbec commit fbdeee8

3 files changed

Lines changed: 26 additions & 5 deletions

File tree

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: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ async function getDeviceFromMount(mountPath: string): Promise<string | null> {
5656
return null;
5757
}
5858

59+
const FLUSH_TIMEOUT_SECS = 10;
60+
const TIMEOUT_EXIT_CODE = 124;
61+
5962
async function flushBlockDevice(devicePath: string): Promise<void> {
6063
const deviceName = devicePath.replace("/dev/", "");
6164
if (!deviceName) {
@@ -75,11 +78,29 @@ async function flushBlockDevice(devicePath: string): Promise<void> {
7578

7679
const startTime = Date.now();
7780
try {
78-
await execAsync(`sudo blockdev --flushbufs ${devicePath}`, {
79-
timeout: 10000,
80-
});
81+
const { stdout, stderr } = await execAsync(
82+
`timeout ${FLUSH_TIMEOUT_SECS} sudo blockdev --flushbufs ${devicePath}; echo "EXIT_CODE:$?"`,
83+
);
8184
const duration = Date.now() - startTime;
8285

86+
// Parse exit code from output
87+
const exitCodeMatch = stdout.match(/EXIT_CODE:(\d+)/);
88+
const exitCode = exitCodeMatch ? parseInt(exitCodeMatch[1], 10) : 0;
89+
90+
if (exitCode === TIMEOUT_EXIT_CODE) {
91+
core.info(
92+
`guest flush timed out for ${devicePath} after ${FLUSH_TIMEOUT_SECS}s`,
93+
);
94+
return;
95+
}
96+
97+
if (exitCode !== 0) {
98+
core.info(
99+
`guest flush failed for ${devicePath} after ${duration}ms: exit code ${exitCode}, stderr: ${stderr}`,
100+
);
101+
return;
102+
}
103+
83104
let afterStats = "";
84105
try {
85106
const { stdout } = await execAsync(`cat ${statPath}`);

0 commit comments

Comments
 (0)