Skip to content

Fix rare ERR_IPC_CHANNEL_CLOSED bug in cluster mode - #244

Merged
siimon merged 2 commits into
prometheus:masterfrom
zbjornson:cluster-ipc
Apr 2, 2019
Merged

siimon merged 2 commits into
prometheus:masterfrom
zbjornson:cluster-ipc

Conversation

@zbjornson

Copy link
Copy Markdown
Contributor

A cluster worker can still be in the list of workers even if its IPC channel has closed (e.g. when the worker exits abruptly). Fix by checking that its IPC channel is open before sending a message.

This happens extremely infrequently (less than once a month for us, running several hundred VMs scraping every 10 seconds), but I've tested in an artificial situation that this makes communication safe:

const cluster = require("cluster");

if (cluster.isMaster) {
	for (let i = 0; i < 4; i++) {
		const worker = cluster.fork();
		// THIS SHOULDN'T LOG WITH THE FIX
		worker.on("error", err => console.log("worker error", err));
	}

	cluster.on("exit", (worker, code, signal) => {
		setTimeout(() => cluster.fork(), 500);
	});

	setInterval(() => {
		for (const id in cluster.workers) {
			if (cluster.workers[id].isConnected()) // TOGGLE THIS LINE
				cluster.workers[id].send({type: "hi!"});
		}
	}, 5);
} else {
	setTimeout(() => process.exit(1), 500);
}

Also removes some code that was for compat with Node.js pre-v6, since v11 of this lib dropped support for pre-v6.

A cluster worker can still be in the list of workers even if its IPC channel has closed (e.g. when the worker exits abruptly). Check that its IPC channel is open before sending a message.
@kevinolson

Copy link
Copy Markdown

@zbjornson any chance we could get this merged and a new tag pushed out as I'm also running into this issue. Thanks!

@tadjohnston tadjohnston mentioned this pull request Apr 1, 2019
@zbjornson

Copy link
Copy Markdown
Contributor Author

@SimenB okay with you?

@siimon
siimon merged commit 5d21477 into prometheus:master Apr 2, 2019
@siimon

siimon commented Apr 2, 2019

Copy link
Copy Markdown
Contributor

Published as 11.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants