Skip to content

_isIdle is not updated properly #9

@slavafomin

Description

@slavafomin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions