Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Epipe error #17

Closed
wants to merge 2 commits into from

2 participants

@jessetane

First, thanks for this awesome library. I get uncaught EPIPE errors if I try to disconnect more than one client at a time though. Even if the errors are caught, the disconnecting service that threw the error is not freed from the registry properly.

Through trial and error I was able to make an example that demonstrates the issue: https://github.com/jessetane/seaport/tree/epipe_error/example/epipe_error and a quick fix that at least lets the example work properly.

This code probably shouldn't be merged though since I didn't know how to write a proper test and I don't totally understand why the issue even occurs in the first place! Hopefully it helps though...

EDIT: added a link to the example

@cheddar

There are commits attached to this issue, has it been fixed?

@cheddar

Or, I guess this is a pull request. Is it legit?

@jessetane

Oh, sorry I haven't played with this in a long time - not sure if the issue still exists or not, but this shouldn't have been a pull request anyways...

@jessetane jessetane closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 11, 2012
  1. @jessetane
  2. @jessetane

    possible EPIPE error fix

    jessetane authored
This page is out of date. Refresh to see the latest.
View
6 example/epipe_error/epipe_error_client.js
@@ -0,0 +1,6 @@
+var seaport = require('../../');
+var http = require('http');
+
+var client = seaport.connect(8080);
+var port = client.register("client@v" + Math.random());
+process.stdin.resume();
View
35 example/epipe_error/epipe_error_server.js
@@ -0,0 +1,35 @@
+var seaport = require('../../');
+var spawn = require('child_process').spawn;
+
+
+// create a server
+var server = seaport.createServer();
+server.listen(8080);
+server.on('register', function () {
+ console.log("service registered, " + server.query().length + " services total")
+});
+server.on('free', function () {
+ console.log("service freed, " + server.query().length + " services total")
+});
+
+
+// create 2 client processes
+var args = [ __dirname + '/epipe_error_client' ];
+var child1 = spawn('node', args);
+var child2 = spawn('node', args);
+
+setTimeout(function () {
+ console.log("------ wait for it ------");
+}, 500);
+
+setTimeout(function () {
+ child1.kill();
+ child2.kill();
+ server.close();
+}, 1000);
+
+
+// show the exception and demonstrate that the corresponding services are still registered
+process.on('uncaughtException', function (err) {
+ console.log(err, '- note that clients with EPIPE errors do not get freed -', server.query());
+});
View
4 index.js
@@ -77,7 +77,9 @@ exports.createServer = function (opts) {
var s = seaport(opts);
s.server = net.createServer(function (c) {
- c.pipe(s.createStream(c.address().address)).pipe(c);
+ var stream = s.createStream(c.address().address);
+ c.on('error', stream.emit.bind(stream, 'error'));
+ c.pipe(stream).pipe(c);
});
s.listen = s.server.listen.bind(s.server);
s.address = s.server.address.bind(s.server);
View
9 lib/seaport.js
@@ -157,12 +157,11 @@ Seaport.prototype.createStream = function (host) {
nodeId = header.id;
});
- var tr = through(write, end);
- s.on('data', tr.emit.bind(tr, 'data'));
- s.on('end', tr.emit.bind(tr, 'end'));
- s.pipe(tr);
+ s.on('data', write);
+ s.on('error', end);
+ s.on('end', end);
- return tr;
+ return s;
function write (buf) {
s.write(buf);
Something went wrong with that request. Please try again.