Network issues on Xcode Cloud brew commands

Hi devs!

I was able to write a ci_post_clone.sh script that installs dependencies before building the app and it was working fine:

brew update
brew install nodenv cocoapods python

However, this week the builds started failing with random network errors on these steps. I checked the Apple Developer System Status and no issues are reported on Xcode Cloud. I don't see what I am doing wrong. Can someone help me? thanks

Examples of errors

Downloading node-v14.18.3-darwin-x64.tar.gz...
-> https://nodejs.org/dist/v14.18.3/node-v14.18.3-darwin-x64.tar.gz
error: failed to download node-v14.18.3-darwin-x64.tar.gz
BUILD FAILED (OS X 12.4 using node-build 4.9.86)
Binary installation failed; try compiling from source with `--compile` flag
Command exited with non-zero exit-code: 1
Cloning into '/Users/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
error: RPC failed; HTTP 502 curl 22 The requested URL returned error: 502
fatal: error reading section header 'shallow-info'
Error: Failure while executing; `git clone https://github.com/Homebrew/homebrew-core /Users/local/Homebrew/Library/Taps/homebrew/homebrew-core --origin=origin --template=` exited with 128.
Error: Failure while executing; `/Users/local/Homebrew/bin/brew tap homebrew/core` exited with 1.
Command exited with non-zero exit-code: 1
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:0d0aeea95f9e7b4ccfa1e8d7f3a83b3b4d604eac1178e4f88ad51d132ad1f7cd?se=2022-07-19T16%3A55%3A00Z&sig=88iMdA3K7Sx5vOXP031AZ6TQf5IwI3HLQa6y901dy3U%3D&sp=r&spr=https&sr=b&sv=2019-12-12
==> Downloading https://ghcr.io/v2/homebrew/core/mpdecimal/manifests/2.5.1
curl: (35) error:02FFF036:system library:func(4095):Connection reset by peer
Error: python@3.9: Failed to download resource "mpdecimal_bottle_manifest"
Download failed: https://ghcr.io/v2/homebrew/core/mpdecimal/manifests/2.5.1

I have the same problem on my builds installing node and cocoapods

Update: I believe this can be Github blocking requests from the XCode Cloud infrastructure because I am also having errors when cloning from Github:

Showing All Messages
+ git clone https://github.com/nodenv/node-build.git /Users/local/.nodenv/plugins/node-build

Cloning into '/Users/local/.nodenv/plugins/node-build'...

error: RPC failed; HTTP 502 curl 22 The requested URL returned error: 502

Yep. This has been like this for a long time thoug. Every now and then builds will fail with the same errors. But the last few weeks it has been completely impossible to gets builds to pass.

Is there any way to add a Github access token for the requests perhaps?

Anyone knows if the following would suffice to make Cocaopods (and other commands) use a personal access token for all Github calls, just in case part of the problem is rate limiting?

git config http.https://github.com.extraheader "Authentication Basic $BASE64_TOKEN"

{
  echo "machine github.com login $GITHUB_USERNAME password $GITHUB_PERSONAL_ACCESS_TOKEN";
} > ~/.netrc
chmod 600 ~/.netrc

(in ci_post_clone.sh)

I am encountering similar issues. I suspect that XCode Cloud limits concurrent network requests, probably to prevent it being abused for staging DDoS attacks.

Setting the following environment variable before running brew appears to result in builds succeeding more reliably

# Limit the number of HTTP requests Git makes in parallel to avoid flakiness in XCode Cloud, which seems to be using a
# proxy that can not handle many concurrent network requests (possibly to prevent being abused for DDoS attacks)
export GIT_HTTP_MAX_REQUESTS=1
Network issues on Xcode Cloud brew commands
 
 
Q