4

ELB occasionally returns 504 to our clients right away (under 1 seconds). Problem is, it's totally random, when we repeat the request right away, it works as it should be.

Anyone have same issue or any idea on this?

Mehmet Fatih Yıldız
  • 1,763
  • 18
  • 25

1 Answers1

2

Does this answers for your quiestion:

Troubleshooting Elastic Load Balancing: HTTP Errors

HTTP 504: Gateway Timeout

Description: Indicates that the load balancer closed a connection because a request did not complete within the idle timeout period.

Cause: The application takes longer to respond than the configured idle timeout.

Solution: Monitor the HTTPCode_ELB_5XX and Latency CloudWatch metrics. If there is an increase in these metrics, it could be due to the application not responding within the idle timeout period. For details about the requests that are timing out, enable access logs on the load balancer and review the 504 response codes in the logs that are generated by Elastic Load Balancing. If necessary, you can increase your back-end capacity or increase the configured idle timeout so that lengthy operations (such as uploading a large file) can complete.

Or this: 504 gateway timeout LB and EC2

Adam Ocsvari
  • 8,056
  • 2
  • 17
  • 30
  • Well, we are aware of getting 504s after 30 seconds but we're receiving this error code within a second after we send the request from the client. Our app might be giving 500 but that shouldn't cause ELB to respond 504 specifically. – Mehmet Fatih Yıldız Jun 23 '15 at 20:45
  • 1
    There is the _second_ cause mentioned on that [Troubleshooting](http://docs.aws.amazon.com/elasticloadbalancing/latest/classic/ts-elb-error-message.html#ts-elb-errorcodes-http504) link: using HTTP keepalive on the backend EC2 HTTP servers *and* making sure that the keepalive timeout is greater than the ELB idle timeout. I've seen cases where the ELB connection to the backend server is kept alive, *but* the backend keepalive settings (by timeout *or* by request count) cause that connection (between ELB and EC2 instance) to be cut regardless of idle timeout. – Castaglia Dec 28 '16 at 04:31
  • This was helpful. I see there is also a `HTTPCode_Target_5XX` metric which I take it is for 5xx errors generated by the backend itself, and not the result of ELB timeout? – IanB May 28 '20 at 01:53
  • 1
    In any case, this is absurd from AWS. How can the ELB not be aware that a connection has been closed by the backend server? In my experience, testing locally with telnet etc.; a connection closed by a backend server is correctly detected by telnet. Why would an ALB ignore that and try to send packets on a closed connection anyway? – Ashesh Apr 13 '22 at 08:02
  • In case of node js event loop blocking operations like sync fs operations can cause 504 errors as well. I read that some guy had 504 errors when the memory limit was hit on the aws instance. We're experiencing random 504 errors on calls that are hit via an interval timer and i wasn't able to find it's cause by now – F.H. Jan 09 '23 at 11:15