socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

Error in Garbage Collector

Open nicoburghi opened this issue 12 years ago • 3 comments

Hi,

Has anyone encountered this error:

TypeError: Cannot use 'in' operator to search for 'issued' in undefined, at Manager.garbageCollection (/node_modules/socket.io/lib/manager.js:1023:21)

I'm using a node js cluster with 3 servers with node.js, socket.io and redis-store

I know I can make a temporaly fix, but I would like to know why I'm getting this error

Thanks.

nicoburghi avatar Dec 06 '13 17:12 nicoburghi

+1 any ideas? I'm getting the same error using Mongo Store

gkorland avatar Feb 06 '14 10:02 gkorland

@nicoburghi how you fix it? I also encountered it. and why this issue is closed? Iam using latest version 0.9.17 but still encountered it

nguyenvansuai avatar Mar 06 '15 02:03 nguyenvansuai

@nguyenvansutt I fix it by asking for undefined befone using the 'in' operator with handshake collection. I'm using socket.io 0.9.16, maybe this issue is fixed in newer versions (maybe versions greater than 1.0.0).

My fixed garbage collection function is like this:

Manager.prototype.garbageCollection = function () {
 // clean up unused handshakes
  var ids = Object.keys(this.handshaken)
    , i = ids.length
    , now = Date.now()
    , handshake;

  while (i--) {
    handshake = this.handshaken[ids[i]];

    if ((typeof handshake != "undefined") &&  (handshake != null)  && ('issued' in handshake) && (now - handshake.issued) >= 3E4) {
      this.onDisconnect(ids[i]);
    }
  }

  ids = Object.keys(this.closed);
  i = ids.length;
  expire = this.get('close timeout') * 1000;

  // clean up the closed sockets
  while (i--) {
    data = this.closed[ids[i]];
    if ('issued' in data && (now - data.issued) >= expire) {
      delete this.closed[ids[i]];
    }
  }

nicoburghi avatar Mar 10 '15 13:03 nicoburghi