'Reasons for Cloudfront ClientCommError and ways to get around it

I am serving few website assets from Cloudfront (backed by S3) and periodically seeing errors like this

2022-02-09  21:20:48    LAX3-C4 0   208.48.9.194    GET my_distribution.cloudfront.net  /my/assets/3636.23f5cbf8445b5e7edb3f.js 000 https://my.site.com/    Mozilla/5.0%20(Windows%20NT%2010.0;%20Win64;%20x64;%20rv:96.0)%20Gecko/20100101%20Firefox/96.0  -   -   Error   7z652evl8PjlvQ65TxEtHHK3qoTU7Tf9F6CW3yHGYxRUYFGxjTlKAw==    my_distribution.cloudfront.net  https   61  0.003   -   TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 Error   HTTP/2.0    -   -   62988   0.000   ClientCommError -   -   -   -

Cloudfront's explanation of ClientCommError: The response to the viewer was interrupted due to a communication problem between the server and the viewer

I have already introduced retries to try and load the resource 3 times before giving up , but it doesn't help for the most part. Also, looking at the location from which resources are requested they are often close by (meaning not from overseas and even on the same coast in US), and my files are pretty small , so the issue can't be the size of a file (ex: 475 B)

What are ways to mitigate such load errors and ensure all resources can be downloaded.



Solution 1:[1]

I wasted two hours on the same thing... Turns out I naively used curl to test it and as curl (sensibly) refused to output binary data to my console nothing was actually pulled from s3 to cloudfront. Once I added --output to curl I started getting hits from Cloudfront.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kimble