mohamed.m.m.hafez / gmail.com wrote:
> Hey all, I've got a pull request at https://github.com/ruby/ruby/pull/1370

I wanted to remove Timeout and use connect_nonblock for a long
time, but it is not simple.  DNS lookup from Socket.sockaddr_in
can take a long time if conn_address is a host name and must be
protected by timeout, too.

The C standard library APIs (getaddrinfo/gethostbyname) do not
implement timeout or non-blocking behavior themselves; so the
only way to stop them is to interrupt them via signal as
Timeout.timeout does.

Instead, we may use lib/resolv.rb from the standard library
which is pure Ruby and does not depend on interrupts and
implements its own timeout using IO.select.  However, resolv.rb
does not automatically use nscd for caching under glibc like
getaddrinfo does.  There may be other incompatibilities, too.

I have not looked at C-ARES or other similar async name resolution
libraries, and it may not be acceptable to depend on non-stdlib.

glibc provides getaddrinfo_a for asynchronous resolution, but
not all the world is glibc and the API is bad:
it relies on signals which may conflict with existing code
or it spawns a new thread which is inefficient

So, the better option may be to fix Timeout.timeout somehow;
possibly exposing a C API which works safely with the VM and
knows only to interrupt at pre-defined "timeout points"
(similar to cancellation points in pthreads, perhaps using
an existing timer_thread).

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>