0
  • Node.js 0.10.26
  • OS X 10.9.2 (also on ubuntu vagrant box)

In two different modules on my system, when I run tests using mocha, I get this error:

{ [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }

Which would normally mean I tried to resolve a nonexistent host. I attempted to spot the problem using dtrace with this script (that I found and slightly modified):

#!/usr/sbin/dtrace -s

#pragma D option quiet

dtrace:::BEGIN
{
    printf("%-20s  %-12s %s\n", "TIME", "LATENCY(ms)", "HOST");
}

pid$target::getaddrinfo:entry
{
    self->host = copyinstr(arg0);
    self->start = timestamp;
}

pid$target::getaddrinfo:return
/self->start/
{
    printf("%d", arg1);
    this->delta = (timestamp - self->start) / 1000000;
    printf("%-20Y  %-12d %s\n", walltimestamp, this->delta, self->host);
    self->host = 0;
    self->start = 0;
}

Using this I can see that every host that gets hit by my tests is either in my host file or is my hostname. The printf("%d", arg1); prints out (I think) the return value of the function. Unfortunately the return value I see is some big number and not 0 or -1 like it should be.

So there is probably something wrong with my dtrace script, but that does not explain my bigger problem:

Why is the host data-proxy not resolved when my hosts file contains 127.0.0.1 data-proxy? and why does this only happen to me when I am running tests with mocha and not when I run my services and hit them manually?

If you want to see the relevant node.js code that gets the errors, feel free to examine mongodb and request because my usage looks like their examples.

joshuten
  • 1
  • 2
  • It looks like it could be that you forgot to close some file handles somewhere. check out: https://github.com/mikeal/request/issues/699 – Daniel Apr 24 '14 at 18:04

2 Answers2

0

Try to cast arg1 in int:

printf("%d\n", (int) arg1);

This is an issue I spotted recently, it may explain why you're getting really big numbers. IIRC, this is because in the kernel arg0 through arg12 are stored in an uint64_t. I don't remember a code path in libdtrace to actually do the cast.

Samuel Gosselin
  • 591
  • 5
  • 5
  • I tried that but I'm still getting weird results. The values of these args seems to depend on how many I print out: arg0 arg1 arg2 is gives different values than arg0 arg1. Do you know of something I could read to learn more about this? – joshuten Apr 25 '14 at 14:30
  • Here is a [gist](https://gist.github.com/joshkuten/11291880) of what I'm trying right now – joshuten Apr 25 '14 at 14:42
0

The big number of arg1 is due to DTrace's Tail-call Optimization. You can check the getaddrinfo source code if possible(if not, please use gdb tool's disassemble command), and you will find the getaddrinfo may call other function.

Nan Xiao
  • 16,671
  • 18
  • 103
  • 164