Troubleshoot NodeJS: application silently rejects requests without any logs

Evgeni Kisel
2 min readMay 10, 2019

--

The issue is rather hard to debug and one of the possible cause is that http header size limit limit exceeded. Node.js has significantly reduced max http header size since versions v6.15.0, v8.14.0, v10.14.0, v11.3.0 (from 80KB to 8KB).

The possible use cases when issue may appear with your application are following:

  • application has a lot of integrations those add additional headers (e.g. google analytics and etc)
  • use of JWT token that may takes KBs
  • heavy usage of custom headers
  • heavy usage of cookies

Actually we did faced with that limitation as a part of our integration flow. The toughest thing is that max header size error appeared from time to time with no any logs. No logs means that there were no even log record about incoming request.

The first clue that we had is that request was actually send to an appropriate service and the service terminated connection (thanks to nginx logs). After that we started makes different experiments with requests and figured out that an issue with amount of headers and run app with max-http-header-size option.

# Setting up max header size via node js parameters
node --max-http-header-size=16384 server.js
# Setting up max header size via pm2
pm2 start server.js --node-args="--max-http-header-size=16384"

As of that moment we fixed that issue but it was required to find out a way to log such sort of errors to avoid similar issues in future. The error can be caught and logged via listening to clientError event on http server instance.

const server = createApp()
.listen(config.port, () => {
log.info(`application is started on port ${config.port}`);
})
.on('clientError', (err, socket) => {
log.error(err);
socket.end('HTTP/1.1 400 Bad Request\r\n\r\n');
});

I’ve created a sample app which you can use to reproduce the issue. Please find it by the link below https://github.com/evgeni-k/max-http-header-size-issue

We are developing data visualization platform. You may try our platform at https://vizydrop.com or https://trello.vizydrop.com

--

--