# Can an 504 Error be thrown by HAProxy itself?

**URL:** <https://discourse.haproxy.org/t/can-an-504-error-be-thrown-by-haproxy-itself/8360>\
**Category:** Help!\
**Created:** [February 4, 2023, 8:37pm UTC](https://discourse.haproxy.org/t/can-an-504-error-be-thrown-by-haproxy-itself/8360 "2023-02-04T20:37:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcmoon](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@jcmoon](https://discourse.haproxy.org/u/jcmoon)\
**Post date:** [February 4, 2023, 8:37pm UTC](https://discourse.haproxy.org/t/can-an-504-error-be-thrown-by-haproxy-itself/8360/1 "2023-02-04T20:37:11Z")

</div>

I am developing an HAProxy extension in Rust using the Lua API endpoints. The code presents an interstitial page unless the user has a cookie to pass it. This library is deployed in Docker alongside Redis for session management.

This works very well, except sometimes (after several hours of production use and never during testing even with simulated traffic), it starts presenting white pages and eventually 504 errors when the timeout is reached.

I would presume that this is the fault of the backend server, but it can be fixed by restarting the HAProxy Docker, implying that it is HAProxy’s fault. However, I never had this problem with HAProxy before (but I did not use Docker). Once the 504 error starts appearing, it does not go away until I restart Docker. I don’t think it’s the fault of the scripts because the interstitial page always works, even when the errors are being thrown.

I’m really at a loss at what it is. It’s hard to reproduce, only happens in production where there’s a time pressure to just restart it, and I’m not finding any valuable debugging information.

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [February 4, 2023, 9:53pm UTC](https://discourse.haproxy.org/t/can-an-504-error-be-thrown-by-haproxy-itself/8360/2 "2023-02-04T21:53:32Z")

</div>

Yes, haproxy will absolutely respond with 504. This happens when the server timeout strikes.

I suggest you analyze haproxy logs and prepare a tcpdump to capture the backend traffic.

AFAIK it is possible to make haproxy misbehave when using unsupported LUA API calls, but I’m not familiar enough with that part to give you something specific to look for.

---

<div class="post-metadata">

**Author:** ![jcmoon](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@jcmoon](https://discourse.haproxy.org/u/jcmoon)\
**Post date:** [February 5, 2023, 6:43am UTC](https://discourse.haproxy.org/t/can-an-504-error-be-thrown-by-haproxy-itself/8360/3 "2023-02-05T06:43:47Z")

</div>

I don’t think that I am using any strange API calls.

There’s two bugs that I’m experiencing:

1. Timeouts leading to 504 pages that persist until the proxy is restarted.
2. Returning blank pages from the backend which only contain headers.

In regards to the second, I am pretty sure this is not the webserver for two reasons. First, it’s happening to static javascript files. Second, the backend headers are being sent, only the content is truncated. This causes haproxy to cache a blank file, and distribute a blank file with caching headers, which causes the clients to cache a blank javascript file. This destroys usability and causes a myriad of issues.

I’m wondering if it can be a Layer 4 problem.

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [February 5, 2023, 10:14am UTC](https://discourse.haproxy.org/t/can-an-504-error-be-thrown-by-haproxy-itself/8360/4 "2023-02-05T10:14:24Z")

</div>

Like I said:

> [@lukastribus](#):
>
> I suggest you analyze haproxy logs and prepare a tcpdump to capture the backend traffic.

If it’s a Layer4 problem, that’s what it will show.
