Luke Bayes | 2 May 20:10
Gravatar

TCPSocket with multiple sub-domains - always a 60 second timeout

Hey Folks,

We've stumbled over a surprising behavior and I wanted to check in to
see if anyone else has experienced this.

We're trying to download and parse RSS feeds. The URL that we're
hitting has two sub-domains (Is that even valid http?)

The official feed URL that we're hitting is:
http://www.ndbc.noaa.gov/rss/ndbc_obs_search.php?lat=45.13N&lon=150.47W

Note the 'www.ndbc' sub-domain.

If we remove the 'www' portion, requests return in under a second (as
expected), but if we leave that sub-domain in place, the request takes
exactly 60 seconds, then returns with a valid result. If we insert
additional sub-domains, we are delayed exactly 60 seconds for each
sub-domain inserted and finally, the request will fail.

We've chased the blocking line to line 574 of net/http.rb

def connect
  D "opening connection to #{conn_address()}..."
  s = timeout(@open_timeout) { TCPSocket.open(conn_address(), conn_port()) }
  D "opened"
...

The behavior is still exhibited when this code is changed to:

def connect
(Continue reading)

Bill Kelly | 2 May 21:04
Picon

Re: TCPSocket with multiple sub-domains - always a 60 second timeout


From: "Luke Bayes" <lbayes <at> patternpark.com>
>
> The official feed URL that we're hitting is:
> http://www.ndbc.noaa.gov/rss/ndbc_obs_search.php?lat=45.13N&lon=150.47W
> 
> Note the 'www.ndbc' sub-domain.
> 
> If we remove the 'www' portion, requests return in under a second (as
> expected), but if we leave that sub-domain in place, the request takes
> exactly 60 seconds, then returns with a valid result. If we insert
> additional sub-domains, we are delayed exactly 60 seconds for each
> sub-domain inserted and finally, the request will fail.

Hmm... on my system, I'm not getting any delays... All these 
responses returned in under a second:

$ ruby -v
ruby 1.8.6 (2007-11-18 patchlevel 5000) [x86_64-linux]

$ irb --simple-prompt
>> require 'socket'
=> false
>> s = TCPSocket.open("www.ndbc.noaa.gov", 80) ; s.close
=> nil
>> s = TCPSocket.open("ndbc.noaa.gov", 80) ; s.close
=> nil
>> s = TCPSocket.open("foo.ndbc.noaa.gov", 80) ; s.close
SocketError: getaddrinfo: Name or service not known
        from (irb):4:in `initialize'
(Continue reading)

Luke Bayes | 2 May 22:48
Gravatar

Re: TCPSocket with multiple sub-domains - always a 60 second timeout

Thanks to your response, I found this thread:
http://www.ruby-forum.com/topic/138634

While the 'do_not_reverse_lookup' fix doesn't have any effect,
requiring 'resolve-replace' did seem to address the problem.

There was a difference in my symptoms though. These other users
claimed an approximately 15 second delay, while mine is exactly 60
seconds every time.

Regardless of the differences, adding the following does fix the issue:

require 'resolve-replace'

As per that discussion, I'll be adding this line to RubyGems in order
to avoid the delays that have appeared there as well.

Thanks,

Luke

> However, you might try:
>
> Socket.do_not_reverse_lookup = true
>
> ...in case it makes any difference?
>
>
> Regards,
>
(Continue reading)


Gmane