Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bolt-js with Jenkins PM2 pipeline deployment brings up an EADDRINUSE port issue #1947

Closed
dianexjeong opened this issue Sep 13, 2023 · 2 comments
Labels
question M-T: User needs support to use the project

Comments

@dianexjeong
Copy link

dianexjeong commented Sep 13, 2023

Hello,
I’m making a slack app with bolt-js, node.js and slack apis.
I've set up OAuth2 authorization, and my app configuration is as follows:

const app = new App({
  signingSecret: process.env.SLACK_SIGNING_SECRET,
  socketMode: false,
  port: 3000,
  clientId: process.env.SLACK_CLIENT_ID,
  clientSecret: process.env.SLACK_CLIENT_SECRET,
  stateSecret: "my-state-secret",
  scopes: [
    "channels:history" // ... and so on
  ],
  installationStore: {
    // emitted the installationStore code here
    storeInstallation: {},
    fetchInstallation: {},
    deleteInstallation: {}
  },
});

I’ve set up a Jenkins CI/CD pipeline with PM2 to deploy node.js to AWS EC2, but I’m encountering some EADDRINUSE issues in the pm2 reloading step.
There are two cores in the EC2 instance, and therefore there are two runs when I run it in PM2 cluster mode.

The following is my ecosystem.config.js :

module.exports = {
  apps: [{
  name: 'project-name',
  cwd: './project-path',
  script: 'npm',
  args: 'start',
  instances: 0,
  exec_mode: 'cluster_mode' 
  }]

When I run the pm2 start ecosystem.config.js command, it runs fine - no port already in use error.
But when I reload the pm2 with pm2 reload, the following error shows:

Error: listen EADDRINUSE: address already in use :::3000
    at Server.setupListenHandle [as _listen2] (node:net:1740:16)
    at listenInCluster (node:net:1788:12)
    at Server.listen (node:net:1876:7)
    at /var/lib/jenkins/workspace/Babywhale-CICD-Pipeline/node_modules/@slack/bolt/dist/receivers/HTTPReceiver.js:177:25
    at new Promise (<anonymous>)
    at HTTPReceiver.start (/var/lib/jenkins/workspace/Babywhale-CICD-Pipeline/node_modules/@slack/bolt/dist/receivers/HTTPReceiver.js:143:16)
    at App.start (/var/lib/jenkins/workspace/Babywhale-CICD-Pipeline/node_modules/@slack/bolt/dist/App.js:241:30)
    at /var/lib/jenkins/workspace/Babywhale-CICD-Pipeline/app.js:320:13
    at Object.<anonymous> (/var/lib/jenkins/workspace/Babywhale-CICD-Pipeline/app.js:322:3)
    at Module._compile (node:internal/modules/cjs/loader:1256:14) {
  code: 'EADDRINUSE',
  errno: -98,
  syscall: 'listen',
  address: '::',
  port: 3000

It says that my port 3000 is already in use and reloads three more times by itself, and eventually the error disappears and my slack app works fine.

Why is the port conflicts happening?

  • Is bolt-js not compatible with AWS EC2 deployment?
  • Should I erase the port option in the app configuration part?
    Is there a possible workaround with the port conflict issue?

Any help would be very appreciated. Thank you in advance!

Reproducible in:

The Slack SDK version

"@slack/bolt": "^3.13.3"

Node.js runtime version

Node.js v18.16.1

OS info

ProductName:		macOS
ProductVersion:		13.2.1
BuildVersion:		22D68

Steps to reproduce:

(Share the commands to run, source code, and project settings)

// ecosystem.config.js

module.exports = {
  apps: [{
  name: 'project-name',
  cwd: './project-path',
  script: 'npm',
  args: 'start',
  instances: 0,
  exec_mode: 'cluster_mode' 
  }]

Expected result:

Screenshot 2023-09-13 at 4 05 27 PM

which is just normal reloading and running of the bolt slack app

Actual result:

Screenshot 2023-09-13 at 4 06 20 PM

which goes through the address already in use error, and proceeds to reload three more times, eventually making it to successfully run the bolt app

Requirements

For general questions/issues about Slack API platform or its server-side, could you submit questions at https://my.slack.com/help/requests/new instead. 🙇

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

@seratch seratch added question M-T: User needs support to use the project and removed untriaged labels Sep 13, 2023
@seratch
Copy link
Member

seratch commented Sep 13, 2023

Hi @dianexjeong, thanks for writing in.

I am not familiar with pm2 reload command, but according to their document, it seems that the command does not terminate the running process when reloading, and probably it tries to start a new one with the same settings: https://pm2.keymetrics.io/docs/usage/cluster-mode/#reload That's why multiple processes try to listen on the same port. I haven't checked how pm2 restart works but trying a different command for the same purpose (I mean live reloading for local development) may help.

@dianexjeong
Copy link
Author

dianexjeong commented Sep 13, 2023

Thank you @seratch for the quick response!

After going through the documents and pm2's Github Issue, I found out that it was a problem that arose from the incompatibility betweenpm2 and npm.

Although this is not so bolt-related, for anyone suffering with similar issues:
you can't run an npm script in the ecosystem.config.json file.

This is my modified ecosystem.config.json:

module.exports = {
  apps: [{
  name: 'Babywhale',
  cwd: './Babywhale-CICD-Pipeline',
  script: 'app.js',
  instances: 0,
  exec_mode: 'cluster_mode'
  }]
}

Issue resolved - appreciate your help again @seratch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question M-T: User needs support to use the project
Projects
None yet
Development

No branches or pull requests

2 participants