diff --git a/lib/tc.js b/lib/tc.js index ca509c7..00d14a1 100644 --- a/lib/tc.js +++ b/lib/tc.js @@ -6,27 +6,25 @@ const delay = (ms) => new Promise((result) => setTimeout(result, ms)); async function getDefaultInterface() { const command = "sudo ip route | awk '/default/ {print $5; exit}' | tr -d '\n'"; - const result = await shell(command); - if (result.stdout.length === 0 && result.stderr.length > 0) { - throw new Error( - 'There was an error getting the default interface:\n\n' + result.stderr - ); - } else if (result.stdout.length === 0) { - // lets do one retry - // The GitHub Actions sometimes cannot find the interface - await delay(1000); + // Retry a few times since GitHub Actions sometimes temporarily loses the default route + for (let attempt = 0; attempt < 3; attempt++) { const result = await shell(command); - if (result.stdout.length === 0) { - const result = await shell('sudo ip route show'); + if (result.stdout.length > 0) { + return result.stdout; + } + if (result.stderr.length > 0) { throw new Error( - `There was an error getting the default interface ${result.stdout}` + 'There was an error getting the default interface:\n\n' + result.stderr ); } - return result.stdout; + await delay(1000); } - return result.stdout; + const result = await shell('sudo ip route show'); + throw new Error( + `There was an error getting the default interface ${result.stdout}` + ); } async function moduleProbe() {