Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

namespace: make sure not to fire `connection` if underlying client cl…

…osed after `next` is called from a middleware
  • Loading branch information...
commit 5f843feb90ddf10674f58cebfb52f9ee4b9b060f 1 parent 01a06b2
@rauchg rauchg authored
Showing with 19 additions and 15 deletions.
  1. +19 −15 lib/namespace.js
View
34 lib/namespace.js
@@ -141,21 +141,25 @@ Namespace.prototype.add = function(client, fn){
var self = this;
this.run(socket, function(err){
process.nextTick(function(){
- if (err) return socket.err(err.data || err.message);
-
- // track socket
- self.sockets.push(socket);
-
- // it's paramount that the internal `onconnect` logic
- // fires before user-set events to prevent state order
- // violations (such as a disconnection before the connection
- // logic is complete)
- socket.onconnect();
- if (fn) fn();
-
- // fire user-set events
- self.emit('connect', socket);
- self.emit('connection', socket);
+ if ('open' == client.conn.readyState) {
+ if (err) return socket.error(err.data || err.message);
+
+ // track socket
+ self.sockets.push(socket);
+
+ // it's paramount that the internal `onconnect` logic
+ // fires before user-set events to prevent state order
+ // violations (such as a disconnection before the connection
+ // logic is complete)
+ socket.onconnect();
+ if (fn) fn();
+
+ // fire user-set events
+ self.emit('connect', socket);
+ self.emit('connection', socket);
+ } else {
+ debug('next called after client was closed - ignoring socket');
+ }
});
});
return socket;

0 comments on commit 5f843fe

Please sign in to comment.
Something went wrong with that request. Please try again.