Lullabot / ddev-node-js-demo

Demo repository for node projects using DDEV
https://www.lullabot.com/articles/nodejs-development-ddev
3 stars 2 forks source link

Svelte app returns 502 #2

Open elabx opened 4 months ago

elabx commented 4 months ago

I am having an issue in a project where one of the proxied node apps is returning a 502, so I tried to reproduce it in your repository and it did exactly the same.

The steps I followed are:

The KeystoneCMS works correctly but the one that should be the svelte app returns a 502 from nginx.

Logs on web:

2024/06/19 03:41:55 [error] 2127#2127: *6 no live upstreams while connecting to upstream, client: 172.19.0.5, server: app.my-project.ddev.site, request: "GET / HTTP/1.1", upstream: "http://localhost/", host: "app.my-project.ddev.site"

Not sure if reproducible by anyone, I had a colleague with the same issue on Linux. I have tried this using ddev 1.23.0 - 1.23.2 with Orbstack and Docker Desktop.

mandrasch commented 4 months ago

Hi @elabx,

I git cloned it, started it with ddev start, got the same 502 on https://app.my-project.ddev.site/

I did

ddev ssh
pm2 stop all
cd svelte/
npm run dev

With that it responded sucessfully on https://app.my-project.ddev.site/ - so I guess it's something about the pm2 / pm2 configuration? (I'm not a pm2 expert myself yet)

mandrasch commented 4 months ago

When I started it again with pm2 Svelte, Svelte(Kit) worked fine - but when I started keystone afterwards with pm2 Keystone again - keystone got the 502 Bad Gateway. 🕵️

mandrasch commented 4 months ago

After I started them both again, it somehow worked in the end - maybe the 502 error is somewhere cached via nginx for some time? 🤔

ddev pm2 logs is also very helpful - it seemed to me, that they both get started after first request in browser and it can take some time for them to come online? But just checked it quickly.

(Here someone suggests increasing proxy_read_timeout - https://stackoverflow.com/a/63026555, but I'm not sure about that)

mandrasch commented 4 months ago

Okay, sorry for all the messages. Should've put this into one report ;-)

After ddev restart everything worked fine.

I deleted the project and started it again

ddev delete -Oy
git clean -fdx
ddev start

There is the 502 error again and I can see in ddev pm2 logs, that there is first an error for both - and only after my first visit of https://app.my-project.ddev.site/ (SvelteKit) is started.

image

So my best current guess is that this has something to do with running npm install in pm2 and not beforehand - which then installs it and can take some time, therefore only the second request can succeed?

See apps.config.js, I guess the command is not ready in time for the first request since it has to install everything before it can be started (= longer than nginx timeout time?):

module.exports = {
  apps : [
    {
      name: "Svelte",
      cwd: "/var/www/html/svelte",
      script: "npm run dev || (rm -rf node_modules && npm install && npm run dev)"
    },
    {
      name: "Keystone",
      cwd: "/var/www/html/keystone",
      script: "npm run dev || (rm -rf node_modules && npm install && npm run dev)"
    }
  ]
}

btw: I'm on ddev version v1.23.2, Orbstack, Mac OSX.

elabx commented 4 months ago

Changing the vite server configuration 127.0.0.1 seems to fix this, can you test on your end @mandrasch?

https://github.com/Lullabot/ddev-node-js-demo/pull/3