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
Topic:
Developer Tools & Services
SubTopic:
Xcode Cloud
Tags: