PM2 throws port already in use error when nuxt ssr deploy

When I deploy my nuxt ssr app, pm2 throws error at below:

Ekran görüntüsü 2021-10-02 182803

Application still online and I can connect to my website but this shouldn’t be normal right? How can I solve that problem? I tried manually change the port but didn’t work.

It may be that PM2 just needs a refresh. This can be done in the deployment section by clicking on the refresh / restart option.

Sorry for late respond. I tried restart multiple times, also tried deploy it again, but issue still occurs. And error continues like that:

Is there still an issue? I see the 200 codes and I can see the site render at alpha.mangagecesi.com. Not that there couldn’t be other issues…

Yeah, as I said before, app is online and maybe the adress is already in use issue caused by another thing. But when I deploy this same app a month ago to cleavr there was no error, so I thought I made a mistake when deploying this time.

Also in this server there are 2 more apps as depo.mangagecesi.com, and v1.mangagecesi.com as file storage and backend api so… maybe they are crushing each other? I don’t know but I will look into it, thank you so much for your time.

I see!

Try running the following on the server command line

lsof -i :9862

Check to see if multiple processes are running on the port. If just one, you might try to stop the process by running kill <pid> and then restart the app to see of that clears it up.

@amiedema had the same problem today where the live site got a bad gateway error.

Restarting the app like you described fixed it. How can i protect myself for the future from this error occuring?

image

We have a check that runs to restart PM2 if we detect this - it should capture this most of the time but could still fall through the cracks. Does it happen consistently? If so, we’d be happy to take a closer look and see what else we might be able to do to help prevent it.

thanks for your reply!

It seems it does not occur consistently. the error itself is perfectly consistent with pm2 restarting the process. But not the failing of restarting the process.

No idea what’s going on.

One more question:
With “Restart pm2” you mean only the affected process and not the whole pm2 service right? So no other sites are affected when restarting?

Yes, that’s correct - only the PM2 process for the app being deployed is restarted.

It seems like an intermittent issue, we’ll investigate.

Hi there,

we still have the issue that we have to restart the app in the Deployment window regularly after a deployment finishes.

We still get a Bad Gateway 502 Error if we don’t do this.

Could you please tell us how your investigation is doing?

Thanks in advance.

Hello!

It’s been an intermittent issue that we haven’t been able to reproduce ourselves… Though, it seems to occur mostly on servers with 1 CPU so we have some ideas that we can implement that hopefully resolves it.

In the meantime, try this and see if it works and let us know if it does or doesn’t.

  1. SSH into the server
  2. Run pm2 status
  3. Delete the processes for that app: pm2 delete <process number>
  4. Back in Cleavr, In the PM2 config file in webapp > settings > build, remove the exec_mode line and change instances from max to 1
  5. Re-deploy the app

You may need to redeploy a couple times to tell if it worked or not, but I’m thinking / hoping that resolves it.

1 Like

Hi @amiedema,

here my findings.

I tested this method on servers with 1 or with 2 CPU and had the same result:

Your fix works!
Without it: Random issues, but more with only 1 CPU.

Could you make it that this “setting” is automatically applied to the WebApps on those kind of servers?

Also, the exec_mode line would be greate to just remove it from all configs?

Thanks for giving us the solution, but it’s a pain to not forget.

Awesome! Thanks for confirming our suspicions. We’ll see what we can do.

1 Like

We just deployed a new improvment - Cleavr now checks whether your server has 1 or multiple cpus and adjusts the config file accordingly. If you get to try it, please let us know if it works or not.

PS: This improvement is only available for non-custom servers. For custom servers, you’d need to adjust configs yourself.

1 Like

@ashok Do i need to do somehting? Or will this be adjusted in the webapp now automatically?

Hello @Houbsi,

We reverted this update due to some technical issues.

We’ll inform you once we re-deploy our new changes.

Hello @Houbsi,

We’ve made additional changes with respect to this feature and re-deployed. Cleavr now checks whether your server has 1 or multiple CPUs and adjusts the PM2 config accordingly to run in either cluster_mode or fork_mode.

This improvement is only available for non-custom servers and the webapp being created now onwards.

If you get to try it, please let us know if it works for you or not.

2 Likes