Skip to content
This repository
Browse code

Merge pull request #87 from gjohnson/fix/reply-errors

ignore closed sockets on reply()
  • Loading branch information...
commit d80889576d84e437b93c40019b58345f25905d26 2 parents 4835ce0 + 2392982
TJ Holowaychuk authored February 28, 2013
9  lib/sockets/rep.js
@@ -50,7 +50,14 @@ RepSocket.prototype.onmessage = function(sock){
50 50
       var args = [].slice.call(arguments);
51 51
       args[0] = args[0] || null;
52 52
       args.push(id);
53  
-      sock.write(self.pack(args));
  53
+      
  54
+      if (sock.writable) {
  55
+        sock.write(self.pack(args));
  56
+        return true;
  57
+      } else {
  58
+        debug('peer went away');
  59
+        return false;
  60
+      }
54 61
     }
55 62
   };
56 63
 };
24  test/test.reqrep.error-reply.js
... ...
@@ -0,0 +1,24 @@
  1
+
  2
+var axon = require('..')
  3
+  , assert = require('better-assert');
  4
+
  5
+var req = axon.socket('req')
  6
+  , rep = axon.socket('rep');
  7
+
  8
+rep.bind(4444);
  9
+req.connect(4444);
  10
+
  11
+rep.on('message', function(msg, reply){
  12
+  setTimeout(function(){
  13
+    assert(reply('ok') === false);
  14
+    rep.close();
  15
+  }, 50);
  16
+});
  17
+
  18
+
  19
+req.on('connect', function(){
  20
+  req.send('hi', function(){});
  21
+  setTimeout(function(){
  22
+    req.close();
  23
+  }, 25);
  24
+});

0 notes on commit d808895

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