Make install_packages resilient to 500 Server Error#3286
Make install_packages resilient to 500 Server Error#3286gsoldevila merged 3 commits intoelastic:masterfrom
install_packages resilient to 500 Server Error#3286Conversation
|
A documentation preview will be available soon. Request a new doc build by commenting
If your PR continues to fail for an unknown reason, the doc build pipeline may be broken. Elastic employees can check the pipeline status here. |
| @@ -15,17 +15,19 @@ RUN echo "deb http://archive.debian.org/debian/ buster main" > /etc/apt/sources. | |||
|
|
|||
| # TODO install_packages calls apt-get update and then nukes the list files after. We should avoid multiple calls to apt-get update..... | |||
There was a problem hiding this comment.
@nik9000 I don't fully understand your comment above, but I wonder if the wrapper script that I'm introducing can help in any way.
There was a problem hiding this comment.
Pull Request Overview
This PR addresses intermittent CI failures caused by 500 Server Errors from package repositories during install_packages operations. It introduces a retry mechanism to make package installation more resilient to transient network failures.
Key Changes:
- Added a new
install_packages.shwrapper script with retry logic (up to 5 attempts with 10-second delays) - Updated all
install_packagescalls in the Dockerfile to use the newinstall_packages.shwrapper
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| install_packages.sh | New wrapper script that adds retry logic around the existing install_packages command to handle transient 500 errors |
| Dockerfile | Copies the wrapper script and updates all package installation commands to use install_packages.sh instead of install_packages |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Check the exit status of the previous command | ||
| if [ $? -eq 0 ]; then | ||
| echo "Packages installed successfully." | ||
| exit 0 # Success, exit the function |
There was a problem hiding this comment.
The comment says "exit the function" but this is a script, not a function. The comment should say "exit the script" for clarity.
| exit 0 # Success, exit the function | |
| exit 0 # Success, exit the script |
| install_packages "$@" | ||
|
|
||
| # Check the exit status of the previous command | ||
| if [ $? -eq 0 ]; then | ||
| echo "Packages installed successfully." | ||
| exit 0 # Success, exit the function | ||
| else | ||
| RETRY_COUNT=$((RETRY_COUNT + 1)) | ||
| if [ $RETRY_COUNT -lt $MAX_ATTEMPTS ]; then | ||
| echo "Installation failed. Retrying in $WAIT_TIME seconds..." | ||
| sleep $WAIT_TIME | ||
| fi | ||
| fi |
There was a problem hiding this comment.
Using $? in a condition is fragile. The exit status should be captured immediately after the command. Consider rewriting as:
if install_packages "$@"; then
echo "Packages installed successfully."
exit 0
else
RETRY_COUNT=$((RETRY_COUNT + 1))
# ... rest of error handling
fiThis ensures the exit status is evaluated correctly without risk of being overwritten by intervening commands.
|
|
||
| # Loop for retry attempts | ||
| while [ $RETRY_COUNT -lt $MAX_ATTEMPTS ]; do | ||
| echo "Attempt $((RETRY_COUNT + 1)) of $MAX_ATTEMPTS: Running install_packages $@" |
There was a problem hiding this comment.
The variable $@ should be quoted as "$@" to properly handle arguments containing spaces or special characters. Without quotes, arguments with spaces will be split into multiple arguments.
| echo "Attempt $((RETRY_COUNT + 1)) of $MAX_ATTEMPTS: Running install_packages $@" | |
| echo "Attempt $((RETRY_COUNT + 1)) of $MAX_ATTEMPTS: Running install_packages \"$@\"" | |
| echo "Arguments: $@" |
reakaleek
left a comment
There was a problem hiding this comment.
LGTM. Thank you for making it more stable.
There is an error in CI. But just looks like syntax error or wrong folder?
I forgot to place the script inside the |
Addresses eventual CI failures such as this one.

The official
install_packagesscript fails if the package repository fails with500 Server Errorwhen trying to fetch the package lists (which happens from time to time).This PR adds a wrapper script with a retry mechanism, so that we don't give up that quickly.