Skip to content

add bash function for retrying ghcr operations - #411

Merged
aptalca merged 4 commits into
monthlyfrom
bash_retry
Oct 14, 2026
Merged

aptalca merged 4 commits into
monthlyfrom
bash_retry

Conversation

@aptalca

@aptalca aptalca commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Lately we have been getting too many failed builds due to ghcr throttling resulting in failed docker pull or build operations.

This PR introduces a bash function that acts as a wrapper for any docker pull and build operation. This wrapper writes the stderr to a file (while still outputting stdout and stderr to terminal for jenkins logging). If the command exits non-zero, it looks for the string retry-after: in stderr and if found, it retries the command up to 5 times with exponential delay.

Some of the error messages we have received in recent builds are as follows:

  • docker: Error response from daemon: error from registry: retry-after: 918.388µs, allowed: 44000/minute
  • Error response from daemon: error from registry: retry-after: 328.54µs, allowed: 44000/minute
  • error from registry: retry-after: 410.616µs, allowed: 44000/minute
  • toomanyrequests: retry-after: 391.125µs, allowed: 44000/minute

They all seem to contain retry-after:

EDIT:
I did a live test with successful operations (nothing failed that time unfortunately):
https://ci.linuxserver.io/job/Docker-Pipeline-Builders/job/docker-synclounge/job/test/5/stages/

I also did local tests where I simulated script failures with stderr output:

Failing script with stderr message not containing retry-after::

$ cat fail.sh 
#!/bin/bash

echo "blah" >&2
exit 134

$ retry_ghcr ./fail.sh 
blah

$ echo $?
134

as expected, the script fails, but is not retried, the function exits with the script's exit code

Failing script with stderr message containing retry-after::

$ cat fail.sh 
#!/bin/bash

echo "blah retry-after:" >&2
exit 134

$ retry_ghcr ./fail.sh 
blah retry-after:
retry: attempt 1/5 failed (exit 134); waiting 1s...
blah retry-after:
retry: attempt 2/5 failed (exit 134); waiting 1s...
blah retry-after:
retry: attempt 3/5 failed (exit 134); waiting 3s...
blah retry-after:
retry: attempt 4/5 failed (exit 134); waiting 2s...
blah retry-after:
retry: ./fail.sh failed after 5 attempts (exit 134)

$ echo $?
134

It is retried 5 times and the function exits with the same code as the script

@aptalca
aptalca requested a review from a team October 9, 2026 02:09
@aptalca aptalca mentioned this pull request Oct 9, 2026
@LinuxServer-CI

Copy link
Copy Markdown
Contributor

I am a bot, here are the test results for this PR for commit 583e5c0 :
https://ci-tests.linuxserver.io/lspipepr/jenkins-builder/efea2443-pkg-efea2443-dev-583e5c0f16c4293e7a28cef3f7cdd6ebccb03f94-pr-411/index.html
https://ci-tests.linuxserver.io/lspipepr/jenkins-builder/efea2443-pkg-efea2443-dev-583e5c0f16c4293e7a28cef3f7cdd6ebccb03f94-pr-411/shellcheck-result.xml

Tag Passed
amd64-efea2443-pkg-efea2443-dev-583e5c0f16c4293e7a28cef3f7cdd6ebccb03f94-pr-411 ✅
arm64v8-efea2443-pkg-efea2443-dev-583e5c0f16c4293e7a28cef3f7cdd6ebccb03f94-pr-411 ✅

@thelamer

thelamer commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

So something I have noticed is that on the gitlab failures no amount of backoff works it just delays the build for an hour. Should we fail fast on gitlab? Fail fast meaning just skip it like it does now without the hour long delay.

@LinuxServer-CI

Copy link
Copy Markdown
Contributor

I am a bot, here are the test results for this PR for commit 1160202 :
https://ci-tests.linuxserver.io/lspipepr/jenkins-builder/efea2443-pkg-efea2443-dev-1160202577dfce8968cdf4b7c40ab79159a486ee-pr-411/index.html
https://ci-tests.linuxserver.io/lspipepr/jenkins-builder/efea2443-pkg-efea2443-dev-1160202577dfce8968cdf4b7c40ab79159a486ee-pr-411/shellcheck-result.xml

Tag Passed
amd64-efea2443-pkg-efea2443-dev-1160202577dfce8968cdf4b7c40ab79159a486ee-pr-411 ✅
arm64v8-efea2443-pkg-efea2443-dev-1160202577dfce8968cdf4b7c40ab79159a486ee-pr-411 ✅

@LinuxServer-CI

Copy link
Copy Markdown
Contributor

I am a bot, here are the test results for this PR for commit 4f80589 :
https://ci-tests.linuxserver.io/lspipepr/jenkins-builder/efea2443-pkg-efea2443-dev-4f80589abb465287c1d5980be72e0dcebbed75cb-pr-411/index.html
https://ci-tests.linuxserver.io/lspipepr/jenkins-builder/efea2443-pkg-efea2443-dev-4f80589abb465287c1d5980be72e0dcebbed75cb-pr-411/shellcheck-result.xml

Tag Passed
amd64-efea2443-pkg-efea2443-dev-4f80589abb465287c1d5980be72e0dcebbed75cb-pr-411 ✅
arm64v8-efea2443-pkg-efea2443-dev-4f80589abb465287c1d5980be72e0dcebbed75cb-pr-411 ✅

@thelamer thelamer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aptalca I touched your code here let me know if you are good, I am. The timeout var is passed full so 600 or 10m will work.

@LinuxServer-CI

Copy link
Copy Markdown
Contributor

I am a bot, the build for PR commit 935764f failed and as a result no CI test was attempted and no images were pushed.

1 similar comment
@LinuxServer-CI

Copy link
Copy Markdown
Contributor

I am a bot, the build for PR commit 935764f failed and as a result no CI test was attempted and no images were pushed.

@LinuxServer-CI

Copy link
Copy Markdown
Contributor

I am a bot, here are the test results for this PR for commit 935764f :
https://ci-tests.linuxserver.io/lspipepr/jenkins-builder/efea2443-pkg-efea2443-dev-935764f5c882b13a506551acdba8bada30e59414-pr-411/index.html
https://ci-tests.linuxserver.io/lspipepr/jenkins-builder/efea2443-pkg-efea2443-dev-935764f5c882b13a506551acdba8bada30e59414-pr-411/shellcheck-result.xml

Tag Passed
amd64-efea2443-pkg-efea2443-dev-935764f5c882b13a506551acdba8bada30e59414-pr-411 ✅
arm64v8-efea2443-pkg-efea2443-dev-935764f5c882b13a506551acdba8bada30e59414-pr-411 ✅

1 similar comment
@LinuxServer-CI

Copy link
Copy Markdown
Contributor

I am a bot, here are the test results for this PR for commit 935764f :
https://ci-tests.linuxserver.io/lspipepr/jenkins-builder/efea2443-pkg-efea2443-dev-935764f5c882b13a506551acdba8bada30e59414-pr-411/index.html
https://ci-tests.linuxserver.io/lspipepr/jenkins-builder/efea2443-pkg-efea2443-dev-935764f5c882b13a506551acdba8bada30e59414-pr-411/shellcheck-result.xml

Tag Passed
amd64-efea2443-pkg-efea2443-dev-935764f5c882b13a506551acdba8bada30e59414-pr-411 ✅
arm64v8-efea2443-pkg-efea2443-dev-935764f5c882b13a506551acdba8bada30e59414-pr-411 ✅

@aptalca
aptalca merged commit fb87c48 into monthly Oct 14, 2026
3 checks passed
@aptalca
aptalca deleted the bash_retry branch October 14, 2026 00:22
@LinuxServer-CI LinuxServer-CI moved this from PRs Approved to Done in Issue & PR Tracker Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants