code: function(server, sock) {
    if (server.requestTimeouts.length === 0) {
      // nothing active
      server.timeoutSet = false;
      return;
    }
  
    // some requests outstanding, check if any have timed-out
    var now = timestamp();
    var soonestTimeout = server.requestTimeouts[0];
  
    if (soonestTimeout <= now) {
      // timeout occurred!
      sock.end();
      server.connected = false;
      server._socket = undefined;
      server.timeoutSet = false;
      server.error(new Error('socket timed out waiting on response.'));
    } else {
      // no timeout! Setup next one.
      var deadline = soonestTimeout - now;
      sock.setTimeout(deadline, function() {
        timeoutHandler(server, sock);
      });
    }
  }
docs: We handle tracking timeouts with an array of deadlines (requestTimeouts), as node doesn't like us setting up lots of timers, and using just one is more efficient anyway.