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

_isIdle is not updated properly #9

Open
slavafomin opened this issue May 31, 2017 · 0 comments
Open

_isIdle is not updated properly #9

slavafomin opened this issue May 31, 2017 · 0 comments

Comments

@slavafomin
Copy link

Hello!

I'm trying to use this module with Express, but I'm getting some weird behavior with this peace of code:

server.on('request', function(req, res) {
  req.socket._isIdle = false;

  res.on('finish', function() {
    req.socket._isIdle = true;
    destroy(req.socket);
  });
});

For some reason, req.socket._isIdle = false; takes no effect, because when I examine req.socket._isIdle in res.on('finish') function I can see it's still set to true.

But, the real problem happens here:

function destroy(socket, force) {
  if (force || (socket._isIdle && isShuttingDown)) {
    socket.destroy();
    delete connections[socket._connectionId];
  }
};

Because socket._isIdle has a incorrect value of false and the socket is not destroyed when shutting down.

This implementation helped me to fix the problem:

server.on('request', function(req, res) {
  var socket = req.socket;
  socket._isIdle = false;

  res.on('finish', function() {
    socket._isIdle = true;
    destroy(socket);
  });
});

Do you have ideas why is this happening? It looks like req.socket references different objects, but it just makes no sense.

@slavafomin slavafomin changed the title _isIdle is not updated properly _isIdle is not updated properly May 31, 2017
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