-
Notifications
You must be signed in to change notification settings - Fork 346
Make install_packages resilient to 500 Server Error
#3286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make install_packages resilient to 500 Server Error
#3286
Conversation
|
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. |
| RUN echo "deb http://archive.debian.org/debian/ buster main" > /etc/apt/sources.list && \ | ||
| echo "deb http://archive.debian.org/debian-security/ buster/updates main" >> /etc/apt/sources.list | ||
|
|
||
| # 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
Copilot
AI
Nov 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
Copilot
AI
Nov 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 $@" |
Copilot
AI
Nov 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.