Skip to content

Commit 9431e61

Browse files
authored
Add retry logic for getting default interface (#102)
1 parent 518407a commit 9431e61

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

lib/tc.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,25 @@ const delay = (ms) => new Promise((result) => setTimeout(result, ms));
66
async function getDefaultInterface() {
77
const command =
88
"sudo ip route | awk '/default/ {print $5; exit}' | tr -d '\n'";
9-
const result = await shell(command);
109

11-
if (result.stdout.length === 0 && result.stderr.length > 0) {
12-
throw new Error(
13-
'There was an error getting the default interface:\n\n' + result.stderr
14-
);
15-
} else if (result.stdout.length === 0) {
16-
// lets do one retry
17-
// The GitHub Actions sometimes cannot find the interface
18-
await delay(1000);
10+
// Retry a few times since GitHub Actions sometimes temporarily loses the default route
11+
for (let attempt = 0; attempt < 3; attempt++) {
1912
const result = await shell(command);
20-
if (result.stdout.length === 0) {
21-
const result = await shell('sudo ip route show');
13+
if (result.stdout.length > 0) {
14+
return result.stdout;
15+
}
16+
if (result.stderr.length > 0) {
2217
throw new Error(
23-
`There was an error getting the default interface ${result.stdout}`
18+
'There was an error getting the default interface:\n\n' + result.stderr
2419
);
2520
}
26-
return result.stdout;
21+
await delay(1000);
2722
}
2823

29-
return result.stdout;
24+
const result = await shell('sudo ip route show');
25+
throw new Error(
26+
`There was an error getting the default interface ${result.stdout}`
27+
);
3028
}
3129

3230
async function moduleProbe() {

0 commit comments

Comments
 (0)