I have a master process that communicates with children processes via UNIX sockets. I am unable to write to the children's sockets when the master process receives a SIGQUIT. I would like the child processes to know that the master is quitting and to gracefully exit.
Communication outside of a SIGQUIT trap works perfectly as expected.
Here's some sample code that reproduces the problem. Remember that CRTL + \ sends a SIGQUIT. (CTRL + C is SIGINT)
Master process: test.js
var net = require("net");
var spawn = require("child_process").spawn;
var socket = new net.Socket();
path_to_worker = process.cwd() + "/test_child.js"
var child = spawn("node", [path_to_worker]);
child.stdout.on('data', function (data) {process.stdout.write(data);})
setTimeout(function() {
socket.connect("/tmp/node-sock", function () {
socket.on('data', function(data) {
console.log(data.toString());
});
});
}, 100)
process.on("SIGQUIT", function () {
socket.write("This won't appear");
});
Child process: test_child.js
var net = require("net");
var socket = new net.Socket();
console.log("Started");
net.createServer(function (server_socket) {
server_socket.on('data', function(data) {
console.log(data.toString());
});
server_socket.write("This will appear");
}).listen("/tmp/node-sock");
The child processes are out of my control, and use a mask to block out all signals except SIGKILL and SIGTERM. If it simply isn't possible to write to their socket during a SIGQUIT trap, is there another way to communicate with them other then sockets?