Recent

Author Topic: 504 Gateway Timeout  (Read 4310 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 19150
  • Glad to be alive.
Re: 504 Gateway Timeout
« Reply #15 on: April 21, 2026, 09:04:52 am »
Besides this, there is the past months a different pattern in server load which I don't know yet how to handle.
I think that pattern is like I described above: many users are using A.I. during development and that means that multiple, seemingly inactive connections can be attributed, but not held, by the same user.
In the case of CoPilot, it acknowledged that it works like that, because it can't drop the connection without loosing context. DeepSeek seems to work similar, frankly I suspect all of them work like that if they cooperate with you: e.g. CoPilot also read responses on the forum during a session and sometimes even before I had the chance. It reads with me, not from me, it also reads from the server.
What you get is connection rot, especially with multiple tabs open in a browser or IDE. A browser tab needs to be specifically closed to drop those connections. A way to mitigate that is a "human" test.

The A.I. helpers do not keep context if a connection is dropped, only a bit client-side so by instinct or knowledge people tend to have the tabs open. (I do). This is easy to test with a simple server, connect, open a connection, ask copilot help with the content of that connection: connections raise from 1 to three, then 2. Close yours, all close.
« Last Edit: April 21, 2026, 09:23:05 am by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2695
Re: 504 Gateway Timeout
« Reply #16 on: April 21, 2026, 09:12:09 am »
That makes some sense
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2695
Re: 504 Gateway Timeout
« Reply #17 on: April 21, 2026, 09:13:58 am »
By me, this night the forum was still inacessible.

And now I can't use any link on the forum (login too): "Cookies error".

I had to go into my browser history to find the direct link to the login page, and now it seems to work.

 :( need to check this, based on the amount of traffic cookie-less traffic, I blocked more cases
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

simone

  • Hero Member
  • *****
  • Posts: 701
Re: 504 Gateway Timeout
« Reply #18 on: April 21, 2026, 09:47:08 am »
By me, this night the forum was still inacessible.

And now I can't use any link on the forum (login too): "Cookies error".

I had to go into my browser history to find the direct link to the login page, and now it seems to work.

I have the same problem, with the cookies page appearing, as happened in the past. To fix it, I have to manually deleting the PHPSESSIONID in the URL.
Microsoft Windows 10/11 64 bit - Lazarus 3.8/4.0 FPC 3.2.2 x86_64-win64-win32/win64

rvk

  • Hero Member
  • *****
  • Posts: 7017
Re: 504 Gateway Timeout
« Reply #19 on: April 21, 2026, 09:57:52 am »
Bad requests are handled by fail2ban and other tools, so these IPs and networks get blocked. Fail2ban however has one problem I found out. It keeps all blocks in an internal sqlite database without removing entries. This DB has grown to 17GB, causing netblock detecting to fail.
Yikes. Maybe add a unique constraint on that table  :D
And find out why Fail2ban could try to add duplicates. If all is correct, that duplicate IP shouldn't even touch the server anymore (because it's already blocked). If it does, then there is something wrong with the blocking itself too. But maybe that's due to the problem with netblock.

How are the IP's blocked in Fail2ban? That's through iptables? (of nftables?)
How many IP's are there in the DB?
« Last Edit: April 21, 2026, 10:06:00 am by rvk »

Fibonacci

  • Hero Member
  • *****
  • Posts: 949
  • Behold, I bring salvation - FPC Unleashed
Re: 504 Gateway Timeout
« Reply #20 on: April 21, 2026, 11:07:21 am »
I took a look at the server response headers:

Server: Apache/2.4.58 (Ubuntu)

A misconfigured Apache is trivial to knock over, and even a well-configured one can fold quite easily. I propose two options, from least invasive:

Variant 1 (low effort): put nginx in front of Apache as a reverse proxy. Apache still handles .htaccess and everything else - the forum config doesn't change.

Variant 2 (long-term): replace Apache entirely with nginx + php-fpm. Catch: if the forum uses .htaccess, those rules must be rewritten into the nginx config. That's why Variant 1 first - small effort, big payoff.

To put some weight behind the claim - I rented a "server by the hour" (so I wouldn't blacklist my own IP by accident) and ran literally two commands on it. The forum went down. Dead. I verified it wasn't responding, waited ~30 seconds, and ended the test.

And to be clear - not a botnet, nothing sophisticated. I can take this server down from a single PC on a connection slower than the forum's.

@Marc - if you give the green light, I'd demonstrate this publicly at a fixed time (suggest 12:00 CEST (10:00 UTC), so in an hour from now), for 5 minutes. Just to show the problem is the HTTP front end itself. Without that it's just "some guy on the forum claims something" - I'd rather show.
FPC Unleashed - inline vars, tuples, statement expressions, array equality, compound assignments, indexed/lazy labels, no-RTTI & more. ⭐ Star it on GitHub!

Fibonacci

  • Hero Member
  • *****
  • Posts: 949
  • Behold, I bring salvation - FPC Unleashed
Re: 504 Gateway Timeout
« Reply #21 on: April 21, 2026, 11:13:38 am »
After the demo I'll explain what's going on - and it's very simple.

Then, escalation order from cheapest to biggest effort:

1. Apache tuning - try an add-on module first. Install, tune, see if it holds. I'll give you the mod names, you do the rest.
2. If not enough - nginx in front of Apache (Variant 1).
3. If still not enough - full Apache removal, nginx + php-fpm (Variant 2).
FPC Unleashed - inline vars, tuples, statement expressions, array equality, compound assignments, indexed/lazy labels, no-RTTI & more. ⭐ Star it on GitHub!

Fibonacci

  • Hero Member
  • *****
  • Posts: 949
  • Behold, I bring salvation - FPC Unleashed
Re: 504 Gateway Timeout
« Reply #22 on: April 21, 2026, 11:16:31 am »
Waiting for the green light from an admin and a confirmed time - then I'll do a short "down" for a few minutes (or maybe I'll fail and the 30-second takedown was just a fluke :D).

I'm online until 14:00-15:00 CEST, so the test can happen anytime before that.
FPC Unleashed - inline vars, tuples, statement expressions, array equality, compound assignments, indexed/lazy labels, no-RTTI & more. ⭐ Star it on GitHub!

Thaddy

  • Hero Member
  • *****
  • Posts: 19150
  • Glad to be alive.
Re: 504 Gateway Timeout
« Reply #23 on: April 21, 2026, 11:27:43 am »
Fred,

Fail2Ban can be configured in many ways.
Usually an IP is blocked for a number of attempts in a given timespan and it should be unblocked after a fixed, configurable, number of efforts. In my case 5 in 1 minute.
But it seems the IP's are held in the database after that: that makes sense if the same ip or block is a recurring visitor, I use fail2ban myself.
This behavior is in principle correct, although the offending IP or range should be removed after a week or so without offenses. If I remember well, that can be also configured (but my servers currently run low to medium traffic).
Recurring offenders can be blocked permanently, although blocking a sub-range can cause problems to some users in the same block, same hoster, and that is a real world scenario.

Cloudflare has a free plan, but there are concerns about Cloudflare.

But fail2ban alone is not the holy grail, and configuring a webserver(s) as a reverse proxy is also not always a good idea, Nitorami.
Although I also run a reverse proxy to keep my servers sane, mostly a bunch of Raspberry Pi's running nature observation camera's, in my case at the cost of high connection rates..(i.e.: server sane,  clients not happy with higher traffic).

Better to use the "Am I human" solution but without the complex puzzles.
« Last Edit: April 21, 2026, 11:41:23 am by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

Fibonacci

  • Hero Member
  • *****
  • Posts: 949
  • Behold, I bring salvation - FPC Unleashed
Re: 504 Gateway Timeout
« Reply #24 on: April 21, 2026, 11:57:24 am »
Cloudflare has a free plan, but there are concerns about Cloudflare.

What concerns? Cloudflare would probably solve the problem.

I suggested it before in the thread about the wiki going down - they went with Anubis instead because they want to stay "independent".

Better to use the "Am I human" solution but without the complex puzzles.

Served by what? Apache? Pointless. Apache stops responding earlier than that. Even if there was no forum, just a blank static page, it would still go down.
FPC Unleashed - inline vars, tuples, statement expressions, array equality, compound assignments, indexed/lazy labels, no-RTTI & more. ⭐ Star it on GitHub!

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12345
  • Debugger - SynEdit - and more
    • wiki
Re: 504 Gateway Timeout
« Reply #25 on: April 21, 2026, 12:12:53 pm »
You need to wait for a reply from Marc. 

He might take a bit of time to respond.

rvk

  • Hero Member
  • *****
  • Posts: 7017
Re: 504 Gateway Timeout
« Reply #26 on: April 21, 2026, 12:22:13 pm »
1. Apache tuning - try an add-on module first. Install, tune, see if it holds. I'll give you the mod names, you do the rest.
What mod would block DDoS with setting SYN_RECV without a completed handshake?
As I understand it, creating a connection to the server:port it sets the SYN_RECV sends back a response and waits for ACK.

This is done in the kernel (as I understand) and doesn't reach the program-process. So mods would be useless in this case, aren't they?

This could be tackled by nftables or other low level guard on network layer level.

BTW. I'm also not sure how nginx would help in this case because these connections attempts (without ACK) wouldn't reach nginx.
Or am I missing something?
« Last Edit: April 21, 2026, 12:27:27 pm by rvk »

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2695
Re: 504 Gateway Timeout
« Reply #27 on: April 21, 2026, 12:26:28 pm »
@Fibonacci
Apache is NOT the bottleneck. Handling PHP is (and yes that is offloaded, so ngnix would suffer too)
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Fibonacci

  • Hero Member
  • *****
  • Posts: 949
  • Behold, I bring salvation - FPC Unleashed
Re: 504 Gateway Timeout
« Reply #28 on: April 21, 2026, 12:28:31 pm »
@Fibonacci
Apache is NOT the bottleneck. Handling PHP is (and yes that is offloaded, so ngnix would suffer too)

Let me start the test, you watch the logs and server load. Tell me when and for how long.
FPC Unleashed - inline vars, tuples, statement expressions, array equality, compound assignments, indexed/lazy labels, no-RTTI & more. ⭐ Star it on GitHub!

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2695
Re: 504 Gateway Timeout
« Reply #29 on: April 21, 2026, 12:29:19 pm »
Let me start the test, you watch the logs and server load. Tell me when and for how long.

I don't need a test, I know where the bottleneck is. And that is hard to solve
« Last Edit: April 21, 2026, 12:31:24 pm by Marc »
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

 

TinyPortal © 2005-2018