Skip to content

socket.server is not defined #5083

Closed
Closed
@unusualbob

Description

@unusualbob

Recently myself and @braydonf were upgrading a project from 0.10.28 to 4.x and found something our connection tracking logic broke and was causing our server to never shutdown. When investigating I found that the server would never emit the close event even if all sockets had been destroyed.

When looking at net.js I noticed that the server._emitCloseIfDrained won't be called if the connection is missing its server property:

https://github.com/nodejs/node/blob/v4.2.6/lib/net.js#L482

Socket.prototype._destroy = function(exception, cb) {
  ...
  if (this.server) {
    COUNTER_NET_SERVER_CONNECTION_CLOSE(this);
    debug('has server');
    this.server._connections--;
    if (this.server._emitCloseIfDrained) {
      this.server._emitCloseIfDrained();
    }
  }

I decided to check for this property when creating my server

server.on('connection', function(socket) {
  console.log(socket.server);
});

I found that in 0.10.x socket.server was defined, but in 4.x it was undefined. I tried to make a test case to replicate it but found I was unable to do so. Luckily @braydonf took another look at it and has managed to replicate it, and is currently tracking down exactly when breakage occurred and said he would follow up on this issue when found. Looks like so far he's narrowed it down to io.js 2.2 -> 2.3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    httpsIssues or PRs related to the https subsystem.netIssues and PRs related to the net subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions