Question

How to solve 504 errors?

I’m building a website that accesses an API powered by Directus, deployed on the DO App Platform. When I load a page with a gallery of images, I often run into 504 and network changed errors for image and XHR requests. I have a test page live on https://fotostrips.nl/beta/test-requests that loads a set of 200 images, which usually triggers the errors for one or more images.

The response headers of a failed image request include:

  • X-Do-Failure-Msg: upstream_reset_before_response_started{connection_termination}
  • X-Do-Failure-Code: UC
  • X-Do-Orig-Status: 503

I don’t see any logs about failed requests in my app’s runtime logs. Directus only shows logs for 200 requests, which leads me to believe it’s not a Directus issue, but a DO issue. How can I find out what’s going on?

Increasing the RAM doesn’t seem to have any effect. And the 504 error, which is usually described as a timeout, happens sometimes instantly for some requests, so not necessarily after a certain time interval.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
January 12, 2024

Hi there,

The 504 Gateway Timeout error indicates that your server, while acting as a gateway or proxy, did not receive a timely response from the upstream server (in this case, your Directus API on the DO App Platform). The X-Do-Failure-Msg and X-Do-Orig-Status: 503 suggest that the issue might be related to the upstream server (Directus) being temporarily unable to handle the request.

What I could suggest checking first is to make sure that your Directus App on DigitalOcean has sufficient resources (CPU and Memory). Heavy image load requests might be overwhelming the server.

The DigitalOcean app platform, does not limit the number of concurrent connections to your app, but each connection consumes system resources and may affect your app’s performance when it is under heavy load. If you are experiencing performance issues related to large numbers of concurrent connections, I would recommend scaling your app to better handle the work load.

Also, Directus relies heavily on its database. Ensure the database is optimized and can handle concurrent requests efficiently and also check the database resources utilization to make sure that it is not the bottleneck.

If you are serving large images, consider resizing, compression, and using efficient formats like WebP to optimize the load times. But also make sure to use a CDN as it can significantly improve the loading times of images and reduce the load on your Directus app itself. Generally speaking, it is best to serve all static files via a CDN.

Let me know how it goes!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.