Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restify inflight request counter leaks when using handleUncaughtExceptions and throwing an exception after connection is aborted #1765

Open
3 tasks done
cprussin opened this issue Mar 26, 2019 · 1 comment

Comments

@cprussin
Copy link
Contributor

cprussin commented Mar 26, 2019

  • 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:

Server.prototype._finishReqResCycle = function _finishReqResCycle(

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)

@cprussin
Copy link
Contributor Author

FYI @mridgway @misterdjules @jdarren

@cprussin cprussin changed the title Restify inflight request counter leaks when using domains and throwing an error after connection is aborted Restify inflight request counter leaks when using handleUncaughtExceptions and throwing an exception after connection is aborted Mar 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant