Skip to content

Suggested fix for : Disconnect event always raising TypeError: Cannot read property 'readyState' of null #477

@abalam666

Description

@abalam666

I have no privilege to push code on any branch, but you might be interested in my little fix for this recurring error on my server with this node-irc lib :

From e6622c7658301a92e9f94e8821bb7cab43a63011 Mon Sep 17 00:00:00 2001
From: Abalam666
Date: Tue, 16 Aug 2016 15:42:25 +0200
Subject: [PATCH] You might be interested in my fix for this recurring error on
 my server with this node-irc lib :

TypeError: Cannot read property 'readyState' of null
  at Client.disconnect (.../node_modules/irc/lib/irc.js:903:18)
  at Timeout._onTimeout (.../server.coffee:76:40)
  at tryOnTimeout (timers.js:224:11)
  at Timer.listOnTimeout (timers.js:198:5)
 'Node could have been crashed...'

---
 lib/irc.js | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/lib/irc.js b/lib/irc.js
index 5abc7f7..12f562b 100644
--- a/lib/irc.js
+++ b/lib/irc.js
@@ -904,21 +904,23 @@ Client.prototype.disconnect = function(message, callback) {
     }
     message = message || 'node-irc says goodbye';
     var self = this;
-    if (self.conn.readyState == 'open') {
-        var sendFunction;
-        if (self.opt.floodProtection) {
-            sendFunction = self._sendImmediate;
-            self._clearCmdQueue();
-        } else {
-            sendFunction = self.send;
+    if (self.conn) {
+        if (self.conn.readyState == 'open') {
+            var sendFunction;
+            if (self.opt.floodProtection) {
+                sendFunction = self._sendImmediate;
+                self._clearCmdQueue();
+            } else {
+                sendFunction = self.send;
+            }
+            sendFunction.call(self, 'QUIT', message);
         }
-        sendFunction.call(self, 'QUIT', message);
-    }
-    self.conn.requestedDisconnect = true;
-    if (typeof (callback) === 'function') {
-        self.conn.once('end', callback);
+        self.conn.requestedDisconnect = true;
+        if (typeof (callback) === 'function') {
+            self.conn.once('end', callback);
+        }
+        self.conn.end();
     }
-    self.conn.end();
 };

 Client.prototype.send = function(command) {
-- 
1.9.5.msysgit.1

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