Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Ignore EPIPE and ECONNRESET errors from stdin #35

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/spawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ function spawn(phantomJsConfig) {

prepareChildProcess(child);

child.stdin.on('error', function (err) {
// Ignore errors if the child has died.
// child.on('exit') will still be fired.
// @see https://github.com/peerigon/phridge/issues/34
if (err.code === 'EPIPE') return;
if (err.code === 'ECONNRESET') return;
throw err;
});
child.stdout.on("data", onStdout);
child.stderr.on("data", onStderr);

Expand Down Expand Up @@ -156,4 +164,4 @@ function disposeChildProcess() {
childProcess.cleanStdout = null;
}

module.exports = spawn;
module.exports = spawn;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"when": "^3.4.2"
},
"devDependencies": {
"chai": "^1.9.1",
"chai": "^2.3.0",
"chai-as-promised": "^4.1.1",
"getport": "^0.1.0",
"istanbul": "^0.3.0",
Expand Down
10 changes: 6 additions & 4 deletions test/Phantom.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,16 +404,18 @@ describe("Phantom", function () {
});
});

it("should be save to call .dispose() multiple times", slow(function () {
it("should be safe to call .dispose() multiple times", slow(function () {
return when.all([
phantom.dispose(),
phantom.dispose(),
phantom.dispose()
]);
}));

it("should be safe to call .dispose() after the process has died", slow(function () {
phantom.childProcess.kill('SIGTERM');
return phantom.dispose();
}));
});

});

});
});
27 changes: 26 additions & 1 deletion test/disposeAll.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,29 @@ describe("disposeAll()", function () {
});
}));

});
it("should ignore EPIPE errors", slow(function () {
var exited = [];

return when.all([
phridge.spawn(),
phridge.spawn(),
phridge.spawn()
])
.then(function (p) {
p[0].childProcess.kill('SIGINT');
return p;
})
.then(function (p) {
p[0].childProcess.on("exit", function () { exited.push(0); });
p[1].childProcess.on("exit", function () { exited.push(1); });
p[2].childProcess.on("exit", function () { exited.push(2); });

return phridge.disposeAll();
})
.then(function () {
exited.sort();
expect(exited).to.eql([0, 1, 2]);
});
}));

});