restify / restify/node-restify
Restify inflight request counter leaks when using handleUncaughtExceptions and throwing an exception after connection is aborted
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.7k
- Forks
- 975
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 5
Description
- 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
Bug Report
Restify Version
Proven reproducible on 8.2.0 and 7.3.0
Node.js Version
Proven reproducible on v8.15.0 and v10.15.1
Expected behaviour
Restify inflight counter should not leak
Inflight requests: 1
Inflight requests: 1
Inflight requests: 1
Inflight requests: 1
...
Actual behaviour
Restify inflight counter leaks
Inflight requests: 1
Inflight requests: 2
Inflight requests: 3
Inflight requests: 4
...
Repro case
const restify = require('restify');
const http = require('http');
const server = restify.createServer({ handleUncaughtExceptions: true });
const delay = 100;
server.pre((req, res, next) => {
console.log(`Inflight requests: ${server.inflightRequests()}`);
next();
});
server.get('/', (req, res, next) => {
setTimeout(() => { throw new Error('foo'); }, delay);
});
server.on('uncaughtException', (req, res) => res.send('foo'));
server.listen(8080, () => {
console.log('Server now up on port 8080');
setInterval(() => {
const req = http.get("http://localhost:8080/").on('error', () => {});
setTimeout(() => req.abort(), delay / 2);
}, delay);
});
Cause
Something in Restify's domain handling causes this function to never get called with res._handlersFinished === true: https://github.com/restify/node-restify/blob/f363b36b0e5176c3f134b345c057ec6199d70b83/lib/server.js#L1347
I'm still working out the precise bug here but I should be able to trace more precisely what the bug is from there and update this ticket with more details.
Are you willing and able to fix this?
Yes (but extra eyes are appreciated)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib/server.js around line 1347, focusing on domain handling, handleUncaughtExceptions, and the _handlersFinished condition described in the report. Run the provided Node.js reproduction and trace why the request completion path is skipped after the connection is aborted. Done means repeated aborted requests no longer increase server.inflightRequests().
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100