Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

node.js - Express post request gives ERR_EMPTY_RESPONSE

I'm building a node.js and express.js web app and it doesn't works as expected when a post request takes longer than 2 mins.
What happens is that after 2 mins my express route is re-called and then, after another 2 mins (4 mins in total) I get this error in the network tab for that post request:

net::ERR_EMPTY_RESPONSE

I read that express has a default timeout set to 2 mins, but that applies only to get requests...

This is my route:

const router = express.Router();

router.post('/', authenticate, async (req, res) => {
  console.log('here');
  setTimeout(function() {
    res.status(201).json({success: true});   
  }, 400000);
})

It prints here to the console when I make the post request, and then it prints again here after 2 minutes.

This is my index file from server:

const app = express();

app.use(bodyParser.json({limit: '50mb'}));
const compiler = webpack(webpackConfig);

app.use(webpackMiddleware(compiler, {
  hot: true,
  publicPath: webpackConfig.output.publicPath,
  noInfo: true
}));
app.use(webpackHotMiddleware(compiler));

app.get('/*', (req, res) => {
  res.sendFile(path.join(__dirname, './index.html'));
});

app.listen(3000, () => console.log('Running on localhost:3000'));
app.timeout = 700000;

There are already 2 weeks since I'm facing this issue and any ideas or solutions would help me a lot. Please let me know if I need to provide more details.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I fixed my issue by removing the web browser's timeout as explained here: https://github.com/expressjs/express/issues/2174


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...