Skip to content

Instantly share code, notes, and snippets.

@schakko
Created May 5, 2012 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schakko/2603955 to your computer and use it in GitHub Desktop.
Save schakko/2603955 to your computer and use it in GitHub Desktop.
DNS not working in forked processes
var cp = require('child_process'),
dns = require('dns');
/** server.js */
// *does* work
dns.resolve4('www.google.com', function(err, addresses) {
console.log("Resolved from service.js");
console.log(addresses);
});
function createChild() {
var child = cp.fork(__dirname + '/worker.js', null, {setsid: true});
child.send({
"host" : 'www.google.com'
});
setTimeout(createChild, 5000);
}
createChild();
var http = require('http'), url = require('url'), dns = require('dns');
// *not* working
dns.resolve4('www.google.com', function(err, addresses) {
console.log("Resolved from worker.js")
console.log(addresses);
});
process.on('message', function(msg) {
console.log("worker.js: message received");
// *not* working
dns.resolve4(msg.host, function(err, addresses) {
console.log("worker.js[message] DNS resolved");
console.log(addresses);
});
process.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment