galaxy: Sometimes a lot of HTTP status codes 520 when accessing Galaxy API

Bug Report

SUMMARY

I’m working on the Ansible changelog / porting guide build (ansible-community/antsibull#103). Both that build, and the ACD build itself, are querying the Galaxy API for all included collections (~60 of them). It often happens to me that I get a lot of 520 HTTP status codes (seems to be a Cloudflare internal error code):

WARNING: aio_session.get('https://galaxy.ansible.com/api/v2/collections/community/azure/versions/0.1.0/', params={'format': 'json'}) failed with status code 520, retrying...
WARNING: aio_session.get('https://galaxy.ansible.com/api/v2/collections/community/azure/versions/0.1.0/', params={'format': 'json'}) failed with status code 520, retrying...
WARNING: aio_session.get('https://galaxy.ansible.com/api/v2/collections/cisco/nxos/versions/?format=json&page=2', params={'format': 'json'}) failed with status code 520, retrying...
WARNING: aio_session.get('https://galaxy.ansible.com/api/v2/collections/google/cloud/versions/0.10.1/', params={'format': 'json'}) failed with status code 520, retrying...
WARNING: aio_session.get('https://galaxy.ansible.com/api/v2/collections/cisco/ios/versions/?format=json&format=json&format=json&page=4', params={'format': 'json'}) failed with status code 520, retrying...
WARNING: aio_session.get('https://galaxy.ansible.com/api/v2/collections/junipernetworks/junos/versions/?format=json&format=json&format=json&format=json&page=5', params={'format': 'json'}) failed with status code 520, retrying...
WARNING: aio_session.get('https://galaxy.ansible.com/api/v2/collections/cisco/ios/versions/?format=json&format=json&format=json&page=4', params={'format': 'json'}) failed with status code 520, retrying...
WARNING: aio_session.get('https://galaxy.ansible.com/api/v2/collections/vyos/vyos/versions/?format=json&format=json&format=json&format=json&page=5', params={'format': 'json'}) failed with status code 520, retrying...
WARNING: aio_session.get('https://galaxy.ansible.com/api/v2/collections/junipernetworks/junos/versions/?format=json&format=json&format=json&format=json&page=5', params={'format': 'json'}) failed with status code 520, retrying...
WARNING: aio_session.get('https://galaxy.ansible.com/api/v2/collections/community/vmware/versions/?format=json&format=json&page=3', params={'format': 'json'}) failed with status code 520, retrying...
WARNING: aio_session.get('https://galaxy.ansible.com/api/v2/collections/community/vmware/versions/?format=json&format=json&page=3', params={'format': 'json'}) failed with status code 520, retrying...
WARNING: aio_session.get('https://galaxy.ansible.com/api/v2/collections/arista/eos/versions/?format=json&format=json&format=json&format=json&format=json&format=json&page=7', params={'format': 'json'}) failed with status code 520, retrying...
WARNING: aio_session.get('https://galaxy.ansible.com/api/v2/collections/cisco/ios/versions/?format=json&format=json&format=json&page=4', params={'format': 'json'}) failed with status code 520, retrying...
WARNING: aio_session.get('https://galaxy.ansible.com/api/v2/collections/cisco/nxos/versions/?format=json&format=json&format=json&page=4', params={'format': 'json'}) failed with status code 520, retrying...
WARNING: aio_session.get('https://galaxy.ansible.com/api/v2/collections/cisco/iosxr/versions/?format=json&format=json&format=json&format=json&page=5', params={'format': 'json'}) failed with status code 520, retrying...
WARNING: aio_session.get('https://galaxy.ansible.com/api/v2/collections/community/vmware/versions/?format=json&format=json&page=3', params={'format': 'json'}) failed with status code 520, retrying...
WARNING: aio_session.get('https://galaxy.ansible.com/api/v2/collections/cisco/iosxr/versions/?format=json&format=json&format=json&format=json&page=5', params={'format': 'json'}) failed with status code 520, retrying...
WARNING: aio_session.get('https://galaxy.ansible.com/api/v2/collections/cisco/nxos/versions/?format=json&format=json&format=json&format=json&page=5', params={'format': 'json'}) failed with status code 520, retrying...
WARNING: aio_session.get('https://galaxy.ansible.com/api/v2/collections/community/vmware/versions/?format=json&format=json&page=3', params={'format': 'json'}) failed with status code 520, retrying...

After adding code to retry the requests (with some increasing delay), it finally almost always completes (before I had to run it 2-10 times until it completed).

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 15 (6 by maintainers)

Commits related to this issue

Most upvoted comments

We’ve doubled the rate limit from 10 requests per second to 20 as a temporary fix and there’s an issue for ansible-galaxy to correctly handle situations where it gets rate limited: https://github.com/ansible/ansible/issues/74191

Sadly galaxy install CLI does not have retry mechanism included in it, which I see as a bug (not missing feature…). Just yesterday I had to implement retry mechanism in ansible-lint specially as it was randomly failing to install collections.

Network operations can fail and will fail, we better have an option in galaxy CLI to retry at least twice. This will likely avoid most glitches.

Hmm, I was assuming that ansible-galaxy collection install would use a larger page size. Or is that only implemented in stable-2.11 / devel? But anyway, having retries and a more efficient API would really help a lot…