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

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

Open
abalam666 opened this issue Aug 16, 2016 · 2 comments

Comments

@abalam666
Copy link

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
@paladox
Copy link
Contributor

paladox commented Nov 15, 2016

@abalam666 hi would you be able to submit the pull request please?

@paladox
Copy link
Contributor

paladox commented Nov 19, 2016

@abalam666 it seems that your fix does not work according to #485 (comment)

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

2 participants