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 puts "opening connection to #{conn_address()}..." s = TCPSocket.open(conn_address(), conn_port()) puts "opened" ... It seems the TCPSocket code is written in C and that's where my ability to track issues pretty much stops. Is this a known issue? Is there a workaround? Can anyone else reproduce with the following code: ----------------------8<----------------------- require 'open-uri' # The following URL times out at 60 seconds and then works url = "http://www.ndbc.noaa.gov/rss/ndbc_obs_search.php?lat=45.13N&lon=150.47W" # The following URL times out at 120 seconds and then fails url = "http://www.www.ndbc.noaa.gov/rss/ndbc_obs_search.php?lat=45.13N&lon=150.47W" # The following URL works fine: #url = "http://ndbc.noaa.gov/rss/ndbc_obs_search.php?lat=45.13N&lon=150.47W" puts "request: #{url}" result = open(url).read puts "result: #{result}" ---------------------->8----------------------- Both Firefox and Safari will load both valid URLs within a second or two. Here is my Ruby version: ruby 1.8.6 (2007-09-24 patchlevel 111) [universal-darwin9.0] I'm on OS X 10.5.2 Any help would be grealy appreciated! Thanks, Luke Bayes
on 02.05.2008 20:16
on 02.05.2008 21:04
From: "Luke Bayes" <lbayes@patternpark.com> > 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' from (irb):4:in `open' from (irb):4 Same on Windows: ruby 1.8.4 (2005-12-24) [i386-mswin32] >> s = TCPSocket.open("www.ndbc.noaa.gov", 80) ; s.close => nil >> s = TCPSocket.open("ndbc.noaa.gov", 80) ; s.close => nil >> s = TCPSocket.open("www.ndbc.noaa.gov", 80) ; s.close => nil >> s = TCPSocket.open("foo.ndbc.noaa.gov", 80) ; s.close SocketError: getaddrinfo: no address associated with hostname. from (irb):6:in `initialize' from (irb):6 However, you might try: Socket.do_not_reverse_lookup = true ...in case it makes any difference? Regards, Bill
on 02.05.2008 22:49
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