Crystal: Fix/Implement own DNS resolver

Created on 27 May 2016  路  6Comments  路  Source: crystal-lang/crystal

The current DNS resolver is broken for some usecases, buggy for others and some setups. We should replace it. See #2568 #2653 #2426.

A resolver written in Crystal is tricky since it would need to hook into OS specific APIs in order to resolve hosts from /etc/hosts, mDNS etc. Most POSIX API is blocking making it tricky to rely on in a language focused on asynchronous IO, see https://github.com/crystal-lang/crystal/issues/2426#issuecomment-221973912

This issue exists to collect issues in the current implementation and ways to mitigate them in possible replacements.

feature stdlib

Most helpful comment

I propose to use C's getaddrinfo until we solve this well in a non-blocking fashion. I think it's preferable to have a blocking thing that works well than a non-blocking thing that's broken (and sometimes in a subtle way). Yes, sometimes a program will have hiccups of up to 5 seconds, but it will eventually work well.

We'd have to revert this commit and a maybe some others.

All 6 comments

A possible implementation route would be using a library such as http://c-ares.haxx.se/ instead of creating it from scratch. This one seems to be portable across POSIX and Windows and can integrate with libevent. For example:

The ares_fds function retrieves the set of file descriptors which the calling application should select on for reading and writing for the processing of name service queries pending on the name service channel identified by channel.

From a very quick search, there are other libraries with similar functionality.

I propose to use C's getaddrinfo until we solve this well in a non-blocking fashion. I think it's preferable to have a blocking thing that works well than a non-blocking thing that's broken (and sometimes in a subtle way). Yes, sometimes a program will have hiccups of up to 5 seconds, but it will eventually work well.

We'd have to revert this commit and a maybe some others.

At this point with Crystal 0.17.4 I cannot use http/client because of this. Is it something related to my system, or is it broken?

Closing: this should have been fixed by #2745.

@ysbaddaden But was it? If so, why #6099 then?

For followers, appears #6099 was caused by a shared v. static linking issue...FWIW...see also #4816

Was this page helpful?
0 / 5 - 0 ratings

Related issues

asterite picture asterite  路  3Comments

lgphp picture lgphp  路  3Comments

Sija picture Sija  路  3Comments

jhass picture jhass  路  3Comments

ArthurZ picture ArthurZ  路  3Comments