pm2
pm2 copied to clipboard
Empty reply after 2 minutes
Hello,
I'm running a server with pm2 and a node/express application.
There are some computational expensive operations that require more than 2 minutes to give a response and I've used an express middleware called connect-timeout to set the request timeout to 5 minutes. (I know it is not a good practice to keep the connection waiting for so long, but this is an internal tool/batch endpoint and it is acceptable).
I've ecountered this issue with pm2: even if the timeout is set to be longer than 2 minutes on the express side, the pm2 closes anyway the connection after 2 minutes.
I did a test using setTimeout and this is the minimal configuration for testing it:
const express = require('express');
const timeout = require('connect-timeout');
redis.flush();
const app = express();
app.use(timeout('5m'));
app.get('/testtimeout/:minutes?', (req, res) => {
const minutes = req.params.minutes ? parseInt(req.params.minutes) : 1;
setTimeout(() => {
res.send('done');
}, 1000 * 60 * minutes);
});
let port = 9018;
//start
app.listen(port, () => {
logger.log('* starting server');
logger.log('* env:', process.env.NODE_ENV);
logger.log('* port:', port);
logger.log('*** * * * ***');
});
module.exports = app;
then I run it by pm2
NODE_ENV=production pm2 start app.js -i 0 --name timeout-app
I use curl to test the endpoint:
curl localhost:9018/testtimeout/3
If the time is more than 2 minutes I get:
curl: (52) Empty reply from server
This doesn't happen if I run it in local using nodemon for developing. Is there a way to extend this time to more than 2 minutes?
Thanks!
Any update on this? I have the same problem.
This seems to be happening to me as well. When an express server is ran using pm2, it times out after two minutes