Skip to content

Commit 75fd5bb

Browse files
committed
Further reduce log flooding when parallel execution terminates early
1 parent b71b3be commit 75fd5bb

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

lib/parallel_worker.js

+27-15
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,14 @@ class ParallelWorker {
2626
// spec files.
2727
for (const errorType of ['uncaughtException', 'unhandledRejection']) {
2828
options.process.on(errorType, error => {
29-
if (this.clusterWorker_.isConnected()) {
30-
this.clusterWorker_.send({
31-
type: errorType,
32-
error: serializeError(error)
33-
});
34-
} else {
35-
// Don't try to report errors after disconnect. If we do, it'll cause
36-
// another unhandled exception. The resulting error-and-reporting loop
37-
// can keep the runner from finishing.
38-
console.error(`${errorType} in Jasmine worker process after disconnect:`, error);
29+
const sent = sendIfConnected(this.clusterWorker_, {
30+
type: errorType,
31+
error: serializeError(error)
32+
});
33+
34+
if (!sent) {
35+
console.error(`${errorType} in Jasmine worker process after disconnect:`,
36+
error);
3937
console.error('This error cannot be reported properly because it ' +
4038
'happened after the worker process was disconnected.'
4139
);
@@ -150,11 +148,7 @@ function forwardingReporter(clusterWorker) {
150148

151149
for (const eventName of eventNames) {
152150
reporter[eventName] = function (payload) {
153-
if (!clusterWorker.isConnected()) {
154-
return;
155-
}
156-
157-
clusterWorker.send({
151+
sendIfConnected(clusterWorker, {
158152
type: 'reporterEvent',
159153
eventName,
160154
payload: {
@@ -170,4 +164,22 @@ function forwardingReporter(clusterWorker) {
170164
return reporter;
171165
}
172166

167+
function sendIfConnected(clusterWorker, msg) {
168+
if (clusterWorker.isConnected()) {
169+
try {
170+
clusterWorker.send(msg);
171+
return true;
172+
} catch (e) {
173+
// EPIPE may be thrown if the worker receives a disconnect between
174+
// the calls to isConnected() and send() above.
175+
if (e.code !== 'EPIPE') {
176+
throw e;
177+
}
178+
}
179+
}
180+
181+
return false;
182+
}
183+
184+
173185
module.exports = ParallelWorker;

0 commit comments

Comments
 (0)