From: "shioimm (Misaki Shioi) via ruby-core" Date: 2025-07-09T10:54:02+00:00 Subject: [ruby-core:122698] [Ruby Bug#21506] Fix timeout in `Addrinfo.getaddrinfo` to actually take effect Issue #21506 has been reported by shioimm (Misaki Shioi). ---------------------------------------- Bug #21506: Fix timeout in `Addrinfo.getaddrinfo` to actually take effect https://bugs.ruby-lang.org/issues/21506 * Author: shioimm (Misaki Shioi) * Status: Open * Assignee: shioimm (Misaki Shioi) * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- ### Description This change fixes an issue where the timeout option in `Addrinfo.getaddrinfo` was not functioning as expected. https://github.com/ruby/ruby/pull/13803/files It also addresses a related issue where specifying `fast_fallback: false` with `resolv_timeout` for `Socket.tcp` and`TCPSocket.new` would have no effect. ### Background The timeout option was originally introduced in: https://github.com/ruby/ruby/commit/6382f5cc91ac9e36776bc854632d9a1237250da7 However, the value was noy used in current implementation: https://github.com/ruby/ruby/blob/3f0e0d5c8bf9046aee7f262a3f9a7524d51aaf3e/ext/socket/raddrinfo.c#L1285 Therefore, even if a timeout is specified and the duration elapses during name resolution, nothing happens. This is clearly not the intended behavior. ### What this change does `Addrinfo.getaddrinfo` has been made interruptible as of Feature #19965. This change uses that feature to interrupt name resolution when the specified timeout period elapses, raising a user-specified timeout error. The timeout can be specified in milliseconds. ### Notes The same issue affects `Socket.tcp` and `TCPSocket.new` when `resolv_timeout` is set along with `fast_fallback: false`. `resolv_timeout` was introduced in the following commits: https://github.com/ruby/ruby/commit/6382f5cc91ac9e36776bc854632d9a1237250da7 https://github.com/ruby/ruby/commit/511fe23fa2bdf1f17faa91e0558be47b5bb62b2a The reason is that with `fast_fallback: false`, these methods internally call the same `rsock_getaddrinfo()` as `Addrinfo.getaddrinfo`. This change addresses that as well. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/