markshust / docker-magento

Mark Shust's Docker Configuration for Magento
https://m.academy/courses/set-up-magento-2-development-environment-docker/
MIT License
2.57k stars 1.01k forks source link

When Xdebug mode is enabled, 502 Bad Gateway error randomly occurs upon page reload #1095

Closed giangvdm closed 7 months ago

giangvdm commented 7 months ago

Description I am using the latest installation (2.4.6-p4) on Ubuntu 22.04 with everything set up correctly. Whenever I enable Xdebug mode, the page randomly gets 502 Bad Gateway error after reloading. I also tried purging then re-installing using different methods (auto, manual, existing project) but all instances pose the same issue.

Screencast from 18-03-2024 17:41:05.webm

Another demonstration of how frustrating it can be when adding products to cart. Screencast from 23-03-2024 09:16:24.webm

I can be sure that I did not encounter this issue in older installation.

Steps To Reproduce

  1. Enable Xdebug mode by running command bin/xdebug enable
  2. Keep refreshing any page

Expected Result Without setting any breakpoints, the page should reload without stopping or any problems.

Actual Result Random 502 Bad Gateway error.

YevhenZvieriev commented 7 months ago

To solve this problem, you must disable Xdebug helper.

Screenshot from 2024-03-16 11-43-23

giangvdm commented 7 months ago

To solve this problem, you must disable Xdebug helper.

Hello, thank you for your solution. But disabling Xdebug Helper extension doesn't do it. magento2docker-502-error-xdebug-disabled I even try accessing the page on a clean browser instance, without Xdebug Helper installed at all, but still no luck.

However, suppose this solution works, will we stop at any breakpoint when Xdebug Helper is disabled?

Anyway, probably there is a misc setting that I missed?

Would love to hear more from everyone.

YevhenZvieriev commented 7 months ago

Hi, @giangvdm

Did you set up Xdebug correctly?

Can you stop at any breakpoint, or it doesn't work?

giangvdm commented 7 months ago

Hi @YevhenZvieriev , thank you for your clarifying question.

I set up Xdebug correctly and able to stop at any breakpoint.

Only when 502 error randomly shows up, it won't stop at any breakpoint, solution is I have to reload the page until the error goes away, which is very frustrating when debugging form submit action such as Checkout.

hanhpv commented 7 months ago

Let's try to check the log.

docker compose logs -f --tail 10 phpfpm

and

docker compose logs -f --tail 10 app
YevhenZvieriev commented 7 months ago

Hi @giangvdm

I have also encountered the 502 error, which is quite unpleasant, especially when debugging processes such as checkout.

However, this can be due to various factors, such as server configuration, server load, or even network issues.

As I said before, if you get a 502 error, I recommend trying to refresh the page several times until the error disappears. I know, it is very frustrating but this may help to resolve the issue temporarily.

I think @markshust will give us a more detailed answer in solving the issue.

giangvdm commented 7 months ago

Let's try to check the log.

Running docker compose logs -f --tail 10 phpfpm shows:

phpfpm-1  | - -  18/Mar/2024:10:26:07 +0000 "GET /index.php" 200
phpfpm-1  | [18-Mar-2024 10:26:07] WARNING: [pool www] child 73 said into stderr: "Mon Mar 18 10:26:07 2024 (73): [Error] APM: Locking APM for 300 seconds for reason: Cannot connect to the agent"
phpfpm-1  | - -  18/Mar/2024:10:27:44 +0000 "GET /index.php" 200
phpfpm-1  | [18-Mar-2024 10:27:44] WARNING: [pool www] child 74 said into stderr: "Mon Mar 18 10:27:44 2024 (74): [Error] APM: Locking APM for 300 seconds for reason: Cannot connect to the agent"
phpfpm-1  | - -  18/Mar/2024:10:27:45 +0000 "GET /index.php" 200
phpfpm-1  | [18-Mar-2024 10:27:45] WARNING: [pool www] child 75 said into stderr: "Mon Mar 18 10:27:45 2024 (75): [Error] APM: Locking APM for 300 seconds for reason: Cannot connect to the agent"
phpfpm-1  | - -  18/Mar/2024:10:27:45 +0000 "GET /index.php" 200
phpfpm-1  | [18-Mar-2024 10:27:45] WARNING: [pool www] child 76 said into stderr: "Mon Mar 18 10:27:45 2024 (76): [Error] APM: Locking APM for 300 seconds for reason: Cannot connect to the agent"
phpfpm-1  | [18-Mar-2024 10:27:46] WARNING: [pool www] child 73 exited on signal 11 (SIGSEGV - core dumped) after 100.834755 seconds from start
phpfpm-1  | [18-Mar-2024 10:27:46] NOTICE: [pool www] child 77 started

And running docker compose logs -f --tail 10 app shows:

app-1  | 172.22.0.1 - - [18/Mar/2024:10:27:45 +0000] "GET / HTTP/2.0" 200 6897 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0" "-"
app-1  | 172.22.0.1 - - [18/Mar/2024:10:27:45 +0000] "GET / HTTP/2.0" 200 6897 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0" "-"
app-1  | 172.22.0.1 - - [18/Mar/2024:10:27:46 +0000] "GET / HTTP/2.0" 502 157 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0" "-"
app-1  | 2024/03/18 10:27:46 [error] 30#30: *5 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 172.22.0.1, server: , request: "GET / HTTP/2.0", upstream: "fastcgi://unix:/sock/docker.sock:", host: "magento.test"
app-1  | 127.0.0.1 - - [18/Mar/2024:10:27:58 +0000] "GET / HTTP/1.1" 301 169 "-" "curl/7.67.0" "-"
app-1  | 2024/03/18 10:27:58 [info] 30#30: *64 client 127.0.0.1 closed keepalive connection
app-1  | 127.0.0.1 - - [18/Mar/2024:10:28:28 +0000] "GET / HTTP/1.1" 301 169 "-" "curl/7.67.0" "-"
app-1  | 2024/03/18 10:28:28 [info] 30#30: *65 client 127.0.0.1 closed keepalive connection
app-1  | 127.0.0.1 - - [18/Mar/2024:10:28:59 +0000] "GET / HTTP/1.1" 301 169 "-" "curl/7.67.0" "-"
app-1  | 2024/03/18 10:28:59 [info] 30#30: *66 client 127.0.0.1 closed keepalive connection

P/s: Hey @hanhpv man, how are you doing? :)

hanhpv commented 7 months ago

Hey, I'm doing good.

Did you enable Blackfire?

bin/root /etc/init.d/blackfire-agent status

I'm not using Markhust setup anymore, but Warden. Just my best guess.

giangvdm commented 7 months ago

@hanhpv

Don't think I have ever. Will give it a try and see what's wrong. Thanks for suggesting.

markshust commented 7 months ago

I haven't ever had issues with Xdebug. I have a few questions:

  1. What is your workflow when debugging on issue with Xdebug?
  2. How long does the request sit spinning before it responds with a 500 error?
  3. Is anyone else having this issue?
giangvdm commented 7 months ago

@markshust One thing I would like to confirm once again, that I set up Xdebug correctly (according to your instructional videos) and can stop at any breakpoint.

To answer your questions:

  1. I run bin/xdebug enable, start Xdebug within PHPStorm, set breakpoints, enable Xdebug Helper on browser (if haven't already), and proceed to the action that triggers the breakpoints. When I'm done debugging, I disable Xdebug mode (bin/xdebug disable) as I understand that Xdebug mode will slow down overall site load speed.
  2. If it is going to be a 502 error, it shows up almost immediately without spinning.
  3. Not that I'm aware of, unfortunately.
YevhenZvieriev commented 7 months ago

I also have this issue.

In my case, I get a 502 error immediately after reloading the page (Ctrl +R), without spinning.

BTW, I also have an old build of docker-magento(44.0.0), I haven't updated it and everything works :) so there is an issue in the newest versions of docker-magento.

Alternatively, consider this as a temporary solution until @markshust or the community fixes the problem.

derekBaldwinGG commented 7 months ago

I'm also experiencing this problem - immediate 502 on about half of page loads (frontend and admin) when xdebug mode is enabled, does not happen when xdebug mode is disabled.

I'm on a 2023 macbook pro, apple m3 max chip, using OrbStack, AC 2.4.6-p3, and am using the 'Existing Projects' setup.

markshust commented 7 months ago

Ah ok - thanks for the clarification @giangvdm! Looks like it's all working properly for you.

A 500 error (503 or otherwise) is typically a higher-level error that doesn't sit on the PHP layer, which is probably why Xdebug isn't catching it. It's a problem on the server-level, not the application-level. Something to do with PHP + Nginx communication.

I'm closing this ticket out, as it feels as though this deviates from the initial issue, but feel free to create a new issue if you feel this 500 is caused by the docker-magento project.

evJoniy commented 7 months ago

@markshust I'm facing the same issue. New or existing project - doesn't matter. Once xdebug is enabled, nginx randomly returns in logs Connection reset by peer. Sometimes, in case of admin panel, the page might load but fail to get the data for it. I've set up greater values for fastcgi_buffer_size and timeouts, but no luck. Template v2.4.6-p3, MacOS. Please advise.

markshust commented 7 months ago

@evJoniy possible resolution at https://github.com/markshust/docker-magento/issues/1085#issuecomment-2016032012 ?

evJoniy commented 7 months ago

@markshust the solution has some effect, but doesn't solve the issue completly. Route checkout/#shipping hasn't failed even once since the fix, but admin dashboard fails almost constantly, even with greater buffer sizes.

rubencougil commented 7 months ago

same problem here, resolution at https://github.com/markshust/docker-magento/issues/1085#issuecomment-2016032012 didn't work for us

frekvent-szabolcs commented 7 months ago

We encountered the same problem. While we had no issues with version 44.0.0, we consistently encountered the issue after upgrading to version 45.1.0. Currently, we are using Magento 2.4.6. Not a solution, but I could resolve the problem by downgrading PHP to markoshust/magento-php:8.1-fpm-1, which eliminated the issue (and I changed nothing else, same config, xdebug enabled..etc).

evJoniy commented 7 months ago

I tried to use downgraded version from colleague who hasn't upgraded, but got no luck

Mavlyan commented 7 months ago

The same issue with markoshust/magento-nginx:1.24 and php 8.2. My fix: Downgraded xdebug to 3.2.1 . Here manual: https://github.com/markshust/docker-magento/issues/1085#issuecomment-2027061052 Thank you dude @madmytrych

markshust commented 7 months ago

See https://github.com/markshust/docker-magento/issues/1085#issuecomment-2052689311

Appears to be a bug with Xdebug itself, specifically https://bugs.xdebug.org/view.php?id=2253

I'll do some additional testing and will attempt to replicate the issue. If I can, I work work on a fix to resolve this.

markshust commented 7 months ago

Ok, this https://github.com/markshust/docker-magento/issues/1095 appears to really be a duplicate of https://github.com/markshust/docker-magento/issues/1085, and the suggested fix has been noted in that thread already and referenced here a couple times, so I'll be closing out this ticket in favor of that one. If you have any updates to this, please followup at https://github.com/markshust/docker-magento/issues/1085