Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make connect_timeout work with DNS resolution #3337

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

haukot
Copy link

@haukot haukot commented Jul 16, 2024

Before it could timeout the connection process, but it still waits for DNS resolution, in some systems for a long time(e.g. on Alpine I see that connection timeouts only after 5 seconds).
It's possible to interrupt the name resolution in ruby 3.3+, tested on 3.3.4 (related issue https://bugs.ruby-lang.org/issues/19965)

irb(main):029* Benchmark.measure do
irb(main):030*   begin
irb(main):031*     Socket.tcp('host', 8080, connect_timeout: 0.01).close
irb(main):032*   rescue
irb(main):033*     puts 'No connection'
irb(main):034*   end
irb(main):035> end
irb(main):036> 
No connection
=> 
#<Benchmark::Tms:0x00007ff9aa0b7128
 @cstime=0.0,
 @cutime=0.0,
 @label="",
 @real=5.006601492001209,
 @stime=0.00031999999999987594,
 @total=0.0014850000000001806,
 @utime=0.0011650000000003047>
irb(main):041* Benchmark.measure do
irb(main):042*   begin
irb(main):043*     Timeout.timeout(0.01) { Socket.tcp('host', 8080).close }
irb(main):044*   rescue
irb(main):045*     puts 'No connection'
irb(main):046*   end
irb(main):047> end
irb(main):048> 
No connection
=> 
#<Benchmark::Tms:0x00007ff9a9f27678
 @cstime=0.0,
 @cutime=0.0,
 @label="",
 @real=0.010416228004032746,
 @stime=0.000212000000000101,
 @total=0.0009450000000004177,
 @utime=0.0007330000000003167>

Before it could timeout connection process, but still wait for DNS
resolution for long time. It's possible to interrupt addrinfo in ruby 3+
@haukot haukot force-pushed the master branch 2 times, most recently from d636073 to 2812c8f Compare July 16, 2024 12:24
@@ -3,6 +3,7 @@
require "rails"
require "rails/test_help"
require "byebug"
require "ostruct"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this tests were failing with

Error:
CompilerTest#test_freshness_on_compile_success:
NameError: uninitialized constant CompilerTest::OpenStruct

e.g. on https://github.com/rails/webpacker/actions/runs/9956692322/job/27507151674#step:4:83

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant