@tjfontaine we spoke about this a bit in #node.js the other day. After we spoke I ran in to some issues and this patch is the result. The tl;dr version is that it looks like dns and native-dns do not use the search path in resolv.conf when the resolve* functions are used.
To go in to a bit more detail, at my company we use DNS to help us discover the zookeeper nodes that are running in a given environment (dev, qa, prod). The way we do this is we perform a lookup for an SRV record (_zookeeper._tcp) and then rely on the search path in resolv.conf to find the right name for the given environment (_zookeeper._tcp.nyc.dev.company.com). This works in other languages without an issue (eg python: dns.resolver.query('_zookeeper._tcp', 'SRV')). We're looking to do more with node, so here we are.
I wrote out the code to do a similar request using dns.resolveSrv from the native dns package and was getting ENOTFOUND. I spent a bit of time reading through the c-ares source, but my c++-fu failed me so I switched over to native-dns, had the same issue with ENOTFOUND, and started reading through the native-dns code to try and find out why. It looks like the lookup() function will use the search path from the platform, but the resolve* functions do not. I'm curious to know why that is. This patch just copies some of the functionality from the lookup functions and uses it in the resolve* functions. With this patch I see the behavior I was expecting, resolve* starts using the search paths.
@tjfontaine we spoke about this a bit in #node.js the other day. After we spoke I ran in to some issues and this patch is the result. The tl;dr version is that it looks like dns and native-dns do not use the search path in resolv.conf when the resolve* functions are used.
To go in to a bit more detail, at my company we use DNS to help us discover the zookeeper nodes that are running in a given environment (dev, qa, prod). The way we do this is we perform a lookup for an SRV record (_zookeeper._tcp) and then rely on the search path in resolv.conf to find the right name for the given environment (_zookeeper._tcp.nyc.dev.company.com). This works in other languages without an issue (eg python: dns.resolver.query('_zookeeper._tcp', 'SRV')). We're looking to do more with node, so here we are.
I wrote out the code to do a similar request using dns.resolveSrv from the native dns package and was getting ENOTFOUND. I spent a bit of time reading through the c-ares source, but my c++-fu failed me so I switched over to native-dns, had the same issue with ENOTFOUND, and started reading through the native-dns code to try and find out why. It looks like the lookup() function will use the search path from the platform, but the resolve* functions do not. I'm curious to know why that is. This patch just copies some of the functionality from the lookup functions and uses it in the resolve* functions. With this patch I see the behavior I was expecting, resolve* starts using the search paths.
Here's some before/after debug output: before: https://gist.github.com/markdrago/0f4542a7cb35011e8fef after: https://gist.github.com/markdrago/52b73c29ef30ec86fef4
It's probably also worth pointing out that my search_path was of the form: [ [ 'nyc.dev.company.com', 'company.com', 'home' ] ]
So I had to pull the inner array out with [0] before working with it.