Skip to content

Commit 7979320

Browse files
authored
CLOUDP-355439: Fix retry.sh script exit code propagation (#2844)
Signed-off-by: jose.vazquez <jose.vazquez@mongodb.com>
1 parent abc2b87 commit 7979320

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

scripts/retry.sh

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,33 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
#!/bin/bash
17+
# retry.sh: Executes a command with retries and exponential backoff.
18+
# Usage: ./retry.sh <command> [args...]
1619

17-
set -euo pipefail
20+
set +o pipefail
1821

19-
max_retries=${MAX_RETRIES:-7}
22+
max_retries=${MAX_RETRIES:-3}
2023
backoff=${BACKOFF:-1}
2124

2225
retries=0
23-
until (( retries == max_retries )) || "${@}"; do
24-
sleep "$(( (retries++)*backoff ))"
26+
exit_status=0
27+
28+
while true; do
29+
"${@}" 2>&1 | cat
30+
31+
exit_status="${PIPESTATUS[0]}"
32+
33+
if [ "$exit_status" -eq 0 ]; then
34+
exit 0
35+
fi
36+
37+
if (( retries == max_retries )); then
38+
echo "❌ Command failed permanently with code $exit_status after $((retries)) retries." >&2
39+
exit "$exit_status"
40+
fi
41+
42+
wait_time=$(( (retries++) * backoff ))
43+
echo "⚠️ Command failed (exit code $exit_status). Retrying in ${wait_time} seconds..." >&2
44+
sleep "${wait_time}"
2545
done
26-
exit $?

0 commit comments

Comments
 (0)