I ran into this error sporadically and could not understand. Googling did not help.
I finally found out. I run a couple of docker containers, among them NGINX
and Apache
. The command at hand addresses a specific container, running Apache
. As it turned out, I also have a cron
job doing some heavy lifting at times running on the same container. Depending on the load this cron
job puts on this container, it was not able to answer my command in a timely manner, resulting in error 52 empty reply from server
or even 502 Bad Gateway
.
I discovered and verified this by plain curl
when I noticed that the process I investigated took less than 2 seconds and all of a sudden I got a 52 error and then a 502 error and then again less than 2 seconds - so it was definitely not my code which was unchanged. Using ps aux
within the container I saw the other process running and understood.
Actually, I was bothered by 502 Bad Gateway
from NGINX
with long running jobs and could not fix it with the appropriate parameters, so I finally gave up and switched these things to Apache
. That's why I was puzzled even more about these errors.
The remedy is simple. I just fired up some more instances of this container with docker service scale
and that was it. docker
load balances on its own.
Well, there is more to this as another example showed. This time I did some repetitious jobs.
I found out that after some time I ran out of memory used by PHP which cannot be reclaimed, so the process died.
Why? Having more than a dozen containers on a 8GB RAM machine, I initially thought it would be a good idea to limit RAM usage on PHP containers to 50MB.
Stupid! I forgot about it, but swarmpit
gave me a hint. I call ini_set("memory_limit",-1);
in the constructor of my class, but that only went as far as those 50MB.
So I removed those restrictions from my compose file. Now those containers may use up to 8GB. The process runs with Apache for hours now and it looks like the problem is solved, memory usage rising to well beyond 100MB.
Another caveat: To easily get and read debug messages, I started said process in Opera
under Windows
. That is fine with errors appearing soon.
However, if the last one is cared for, quite naturally the process runs and runs and memory usage in the browser builds up, eventually making my local machine unusable. So if that happens, kill this tab and the process keeps running fine.