restify / node-restify

The future of Node.js REST development

Home Page:http://restify.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Request hangs when its request header size exceeds

nigelis opened this issue · comments

  • Used appropriate template for the issue type
  • Searched both open and closed issues for duplicates of this issue
  • Title adequately and concisely reflects the feature or the bug

Restify Version: v8.5.2
Node.js Version: v16.13.2

Expected behaviour

Response with status code 400 Bad Request or 431 Request Header Fields Too Large.

Actual behaviour

The request hangs without any response.

Repro case

const server = restify.createServer();

// Uncomment, then it is responded with status code 431 for request with too large headers.
// server.server.removeAllListeners('clientError');

server.get('/api', (req, res, next) => { res.send(200); next(); });
server.listen(8080);

Request with lots of large headers, the total size exceeds 16KB.

Cause

Restify forwards several events from the internal server to itself.

node-restify/lib/server.js

Lines 144 to 151 in 5c7eb95

this.proxyEvents = [
'clientError',
'close',
'connection',
'error',
'listening',
'secureConnection'
];

node-restify/lib/server.js

Lines 204 to 206 in 5c7eb95

this.proxyEvents.forEach(function forEach(e) {
self.server.on(e, self.emit.bind(self, e));
});

Forwarding the event clientError breaks the error handling of the internal server, thus the request hangs.

Are you willing and able to fix this?

Yes.

Because no event listener for clientError is added by default, it is OK to not forward the event.