Pm2: Have to send 'ready' message twice for wait-ready to work

Created on 7 May 2019  路  7Comments  路  Source: Unitech/pm2

What's going wrong?

I seem to have to send the 'ready' message twice in conjunction with the wait-ready flag, else it waits until listen-timeout is reached.

How could we reproduce this issue?

pm2 start build/server/main.js --name myapp -i 2 --wait-ready --listen-timeout 20000
pm2 reload myapp --parallel 1

In main.ts

nodeServer = server.listen(config.port, function(){
        console.log('Server running on port ' + config.port);
        //Notify pm2 that the instance is ready to accept connections
        if(process.send){
            //Due to a bug, we have to send this twice
            process.send('ready');
            process.send('ready');
        }
    });

Sending the message twice as above works, whereas sending it once causes listen-timeout to be reached.

Supporting information

Using pm2 3.5 and node 11.12.

Bug

All 7 comments

@benstevens48 dude, how did you figure this out?! I have been struggling with this bug for almost a year now! Thank you for posting this issue and workaround. I owe you one.

@benstevens48 dude, how did you figure this out?! I have been struggling with this bug for almost a year now! Thank you for posting this issue and workaround. I owe you one.

I thought it might be a timing issue so put process.send('ready') in various places in my startup code without removing the original process.send('ready') and it worked wherever I put it, but when I removed the original statement it stopped working - so eventually came to this conclusion.

I think it is quite old issue. How is it going?

@Unitech, @sharpart555, @benstevens48 I have this issue and made PR with fix
https://github.com/Unitech/pm2/pull/4376

merged, will land on [email protected]

Available in PM2 4.1.0

npm install pm2@latest -g
pm2 update
Was this page helpful?
0 / 5 - 0 ratings

Related issues

phra picture phra  路  3Comments

ldarren picture ldarren  路  3Comments

waygee picture waygee  路  4Comments

mario-mui picture mario-mui  路  3Comments

lefam picture lefam  路  3Comments