RejectedSoftware Forums

Sign up

requestHTTP can't resolve host names

Hi!

I have a problem with host name resolving - requestHTTP can't resolve any name, but works with IP addresses only. For example, I can dig or NSLookup api.sendgrid.com:

crimaniak@crimaniak-X550LB:~$ nslookup api.sendgrid.com
Server:		8.8.8.8
Address:	8.8.8.8#53

Non-authoritative answer:
Name:	api.sendgrid.com
Address: 159.122.224.201
Name:	api.sendgrid.com
Address: 159.122.224.200

but next code gives me exception:

	enum mailEndpoint = "https://api.sendgrid.com/v3/mail/send";
...	
		return requestHTTP(mailEndpoint, (scope HTTPClientRequest request){
				request.method = HTTPMethod.POST;
				request.headers["Authorization"] = "Bearer "~apiKey;
            ...
        });				

From both static unittest block and real test page requested from browser. How to debug this issue?
Thanks.

object.Exception@../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/core/drivers/libevent2.d(270): Failed to lookup host 'api.sendgrid.com': nodename nor servname provided, or not known
----------------
/usr/include/dmd/phobos/std/exception.d:405 pure @safe void std.exception.bailOut!(Exception).bailOut(immutable(char)[], ulong, const(char[])) [0x6c26f7]
/usr/include/dmd/phobos/std/exception.d:363 pure @safe bool std.exception.enforce!(Exception, bool).enforce(bool, lazy const(char)[], immutable(char)[], ulong) [0x6c267a]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/core/drivers/libevent2.d:270 vibe.core.net.NetworkAddress vibe.core.drivers.libevent2.Libevent2Driver.resolveHost(immutable(char)[], ushort, bool) [0x733fab]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/core/net.d:45 vibe.core.net.NetworkAddress vibe.core.net.resolveHost(immutable(char)[], ushort, bool) [0x7522e7]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/core/net.d:40 vibe.core.net.NetworkAddress vibe.core.net.resolveHost(immutable(char)[], std.socket.AddressFamily, bool) [0x75223e]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/http/client.d:594 bool vibe.http.client.HTTPClient.doRequest(scope void delegate(vibe.http.client.HTTPClientRequest), bool*, bool, std.datetime.SysTime) [0x6f9829]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/http/client.d:515 bool vibe.http.client.HTTPClient.doRequestWithRetry(scope void delegate(vibe.http.client.HTTPClientRequest), bool, out bool, out std.datetime.SysTime) [0x6f9463]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/http/client.d:486 vibe.http.client.HTTPClientResponse vibe.http.client.HTTPClient.request(scope void delegate(vibe.http.client.HTTPClientRequest)) [0x6f927b]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/http/client.d:95 vibe.http.client.HTTPClientResponse vibe.http.client.requestHTTP(vibe.inet.url.URL, scope void delegate(scope vibe.http.client.HTTPClientRequest), const(vibe.http.client.HTTPClientSettings)) [0x6f7eba]
../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/http/client.d:71 vibe.http.client.HTTPClientResponse vibe.http.client.requestHTTP(immutable(char)[], scope void delegate(scope vibe.http.client.HTTPClientRequest), const(vibe.http.client.HTTPClientSettings)) [0x6f7b82]
src/vendor/sendgrid/api/v3.d:25 vibe.http.client.HTTPClientResponse v3.SendGrid.sendMail(immutable(char)[], immutable(char)[], immutable(char)[]) [0x6f5d0c]
src/vendor/sendgrid/api/v3.d:43 void v3.__unittestL38_2() [0x6f5f18]
...

Re: requestHTTP can't resolve host names

On Tue, 08 Nov 2016 21:49:07 GMT, Alexey Kulentsov wrote:

Hi!

I have a problem with host name resolving - requestHTTP can't resolve any name, but works with IP addresses only. For example, I can dig or NSLookup api.sendgrid.com:

crimaniak@crimaniak-X550LB:~$ nslookup api.sendgrid.com
Server:		8.8.8.8
Address:	8.8.8.8#53

Non-authoritative answer:
Name:	api.sendgrid.com
Address: 159.122.224.201
Name:	api.sendgrid.com
Address: 159.122.224.200

but next code gives me exception:

	enum mailEndpoint = "https://api.sendgrid.com/v3/mail/send";
...	
		return requestHTTP(mailEndpoint, (scope HTTPClientRequest request){
				request.method = HTTPMethod.POST;
				request.headers["Authorization"] = "Bearer "~apiKey;
            ...
        });				

From both static unittest block and real test page requested from browser. How to debug this issue?
Thanks.

object.Exception@../../.dub/packages/vibe-d-0.7.30/vibe-d/source/vibe/core/drivers/libevent2.d(270): Failed to lookup host 'api.sendgrid.com': nodename nor servname provided, or not known
(...)

Would be interesting to see if there are any related known issues/questions for libevent. There is a ticket that might be related, where libevent fails to use a second configured name server for lookups: #1612

Does your resolv.conf (or the files in /etc/resolvconf/resolf.conf.d/ or the NetworkManager configuration) contain multiple name servers?

Re: requestHTTP can't resolve host names

On Thu, 10 Nov 2016 08:47:41 GMT, Sönke Ludwig wrote:

Would be interesting to see if there are any related known issues/questions for libevent. There is a ticket that might be related, where libevent fails to use a second configured name server for lookups: #1612

Does your resolv.conf (or the files in /etc/resolvconf/resolf.conf.d/ or the NetworkManager configuration) contain multiple name servers?

Yes! I found old unreachable DNS server, not updated after provider change. nslookup and other utilities do fallback to second server 8.8.8.8, but not libevent. After removing old server all works as expected. Thanks again!