Permalink
Browse files

ignore closed sockets on reply(). fixes #82

  • Loading branch information...
1 parent 4835ce0 commit 2392982218737ebd678cb29661ad3d191cc5726a Garrett Johnson committed Feb 28, 2013
Showing with 32 additions and 1 deletion.
  1. +8 −1 lib/sockets/rep.js
  2. +24 −0 test/test.reqrep.error-reply.js
View
@@ -50,7 +50,14 @@ RepSocket.prototype.onmessage = function(sock){
var args = [].slice.call(arguments);
args[0] = args[0] || null;
args.push(id);
- sock.write(self.pack(args));
+
+ if (sock.writable) {
+ sock.write(self.pack(args));
+ return true;
+ } else {
+ debug('peer went away');
+ return false;
+ }
}
};
};
@@ -0,0 +1,24 @@
+
+var axon = require('..')
+ , assert = require('better-assert');
+
+var req = axon.socket('req')
+ , rep = axon.socket('rep');
+
+rep.bind(4444);
+req.connect(4444);
+
+rep.on('message', function(msg, reply){
+ setTimeout(function(){
+ assert(reply('ok') === false);
+ rep.close();
+ }, 50);
+});
+
+
+req.on('connect', function(){
+ req.send('hi', function(){});
+ setTimeout(function(){
+ req.close();
+ }, 25);
+});

0 comments on commit 2392982

Please sign in to comment.