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

null reference in cleanup deflate #664

Closed
beatjoerg opened this issue Jan 11, 2016 · 3 comments
Closed

null reference in cleanup deflate #664

beatjoerg opened this issue Jan 11, 2016 · 3 comments

Comments

@beatjoerg
Copy link

I randomly get this error:

TypeError: Cannot read property 'close' of null
at InflateRaw.Zlib.close (zlib.js:469:15)
at PerMessageDeflate.cleanup (ws/lib/PerMessageDeflate.js:82:46)

Can someone have a look at this issue. It looks to me, that something that is already closed get closed again...

@darrachequesne
Copy link
Contributor

Weird, there must be some kind of race condition here (with https://github.com/websockets/ws/blob/master/lib/PerMessageDeflate.js#L259), since this._inflate is checked against null value just before:

PerMessageDeflate.prototype.cleanup = function() {
  if (this._inflate) {
    if (this._inflate.writeInProgress) {
      this._inflate.pendingClose = true;
    } else {
      if (this._inflate.close) this._inflate.close(); //L82
      this._inflate = null;
    }
  }
  ...

One quick fix would be to catch any exception here https://github.com/websockets/ws/blob/master/lib/WebSocket.js#L956

if (this.extensions[PerMessageDeflate.extensionName]) {
  try {
    this.extensions[PerMessageDeflate.extensionName].cleanup(); }
  catch (e) {}
}

@headlessme
Copy link

I'm seeing the same issue

TypeError: Cannot read property 'close' of null
    at InflateRaw.Zlib.close (zlib.js:465:15)
    at PerMessageDeflate.cleanup (/var/app/current/node_modules/ws/lib/PerMessageDeflate.js:82:46)
    at WebSocket.cleanupWebsocketResources (/var/app/current/node_modules/ws/lib/WebSocket.js:957:54)
    at emitNone (events.js:72:20)
    at Socket.emit (events.js:166:7)
    at endReadableNT (_stream_readable.js:905:12)
    at nextTickCallbackWith2Args (node.js:441:9)
    at process._tickDomainCallback (node.js:396:17)

@headlessme
Copy link

Looks like this might actually be a problem with zlib:

var zlib = require('zlib');
var inflate = zlib.createInflateRaw(15);
inflate.on('error', function(e) {  });
inflate.write('something invalid');
setTimeout(function(){
    inflate.close();  
}, 100);

output:

$ node inflate-close.js 
zlib.js:465
  this._handle.close();
              ^

TypeError: Cannot read property 'close' of null
    at InflateRaw.Zlib.close (zlib.js:465:15)
    at null._onTimeout (/tmp/inflate-close.js:8:13)
    at Timer.listOnTimeout (timers.js:92:15)

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

4 participants