Watir: get sometimes a Net::ReadTimeout error by launching chrome browser - ruby

I just use a watir script to download sequential status infos from a server. In most cases it works fine, but sometimes I get an Net::ReadTimeout error. I don't know why?
Code:
require "rubygems"
require "watir"
Watir.default_timeout = 180 # seconds – default is 60
prefs = { :download => { :prompt_for_download => false, :default_directory => path } }
browser = Watir::Browser.new :chrome, :switches => %w[--no-sandbox], :prefs => prefs
browser.goto 'https://www...'
...
Error Message:
/usr/lib/ruby/2.3.0/net/protocol.rb:158:in `rbuf_fill': Net::ReadTimeout (Net::ReadTimeout)
from /usr/lib/ruby/2.3.0/net/protocol.rb:136:in `readuntil'
from /usr/lib/ruby/2.3.0/net/protocol.rb:146:in `readline'
from /usr/lib/ruby/2.3.0/net/http/response.rb:40:in `read_status_line'
from /usr/lib/ruby/2.3.0/net/http/response.rb:29:in `read_new'
from /usr/lib/ruby/2.3.0/net/http.rb:1437:in `block in transport_request'
from /usr/lib/ruby/2.3.0/net/http.rb:1434:in `catch'
from /usr/lib/ruby/2.3.0/net/http.rb:1434:in `transport_request'from /usr/lib/ruby/2.3.0/net/http.rb:1407:in `request'
from /usr/lib/ruby/2.3.0/net/http.rb:1400:in `block in request'
from /usr/lib/ruby/2.3.0/net/http.rb:853:in `start'
from /usr/lib/ruby/2.3.0/net/http.rb:1398:in `request'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/default.rb:103:in `response_for'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/default.rb:57:in `request'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/bridge.rb:653:in `raw_execute'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/bridge.rb:124:in `create_session'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/bridge.rb:88:in `initialize'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/chrome/bridge.rb:41:in `initialize'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/common/driver.rb:61:in `new'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/common/driver.rb:61:in `for'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver.rb:82:in `for'
from /var/lib/gems/2.3.0/gems/watir-6.0.2/lib/watir/browser.rb:46:in `initialize'
from /var/www/jobs/ubuntu.rb:110:in `new'from /var/www/jobs/ubuntu.rb:5:in `<main>'
I just looking for a reason on this?
Is it possible the customize the settings on firefox? What is wrong?
Watir Version: 6.0.2
Selenium Version: 3.0.1
Browser Chrome Version: 57.0.2987.110
Chrome Driver Version: 2.29.461571
OS Version: Ubuntu 16.04.3 LTS

I had a similar problem when running my Selenium Webdriver tests on our Ubuntu Jenkins build server, but I never experienced this locally on my Windows PC. Like your problem, it was an intermittent issue. I spent quite a lot of time researching it and couldn't get to the bottom of it, I did however put it down to a Ruby/ Ubuntu issue rather than an issue with the test, because of this, I decided to rescue the Net::ReadTimeout error and retry. Since implementing the following example, I haven't experienced this problem again.
attempts = 0 # has to be outside the begin/rescue to avoid infinite loop
begin
profile = Selenium::WebDriver::Chrome::Profile.new
$driver = Selenium::WebDriver.for :chrome, :profile => profile,
$driver.manage.window.resize_to(1280, 720)
rescue Net::ReadTimeout => e
if attempts == 0
attempts += 1
retry
else
raise
end
end
You should be able to briefly modify the above example to work with Watir. It basically captures the error and retries/ re-runs the test.

First of all, Watir.default_timeout has nothing to do with error you have stated, So even if you increase the time of default_timeout, nothing would happen in this place, Watir.default_timeout is applicable only when you find an element, not for page_load.
Second off, this problem only exist in Ruby Selenium Binding, not in Java Selenium Binding, for an example, If you set
driver.manage.timeouts.page_load=120 (WATIR doesn't provide any systax to this selenium equivalent, so to write this code in WATIR, please invoke b.driver.)
This time settings is only applicable for goto method, it's not affecting anything when you click a button and waiting for a page load, the default timeout for page_load is 60 seconds, that would anyhow wait for 60 seconds, but what you set doesn't affect or change this 60 seconds. But this problem is not there for Selenium Java Binding, it's working properly.
Okay, the question is, you are using it for goto so why not you can use the page_load to set the time?
Actually you can decrease the time, but you can't increase the time beyond 60 seconds. But I found some workaround for this problem, but I strongly recommend you to file a bug in ruby selenium binding.
So it's not a WATIR problem, it's the problem in Ruby selenium binding.

Finally i tested also the solution with firefox and get the described error:
/var/lib/gems/2.1.0/gems/selenium-webdriver-3.0.1/lib/seleni‌​um/webdriver/remote/‌​response.rb:69:in 'assert_ok':
TypeError: Given platformVersion [object String] "any", but current platform version is [object String] "3.16.0-4-amd64"
(Selenium::WebDriver::Error::SessionNotCreatedError)
It seems to be a problem with a specific firefox and geckodriver version. I tested many combinations. This versions work without the TypeError:
Firefox 51.0.1
geckodriver 0.11.1
Thanks to dan.brown

Related

Watir webdriver not working as expected

I tried to execute a simple browser test
require 'rubygems'
require 'watir-webdriver'
b = Watir::Browser.new :firefox
b.goto 'http://www.google.com/'
The browser launched and closed immediately throwing the following error
c:/ruby22/lib/ruby/2.2.0/net/http/generic_request.rb:25:in `initialize': HTTP request path is empty (ArgumentError)
from c:/ruby22/lib/ruby/2.2.0/net/http/request.rb:14:in `initialize'
from c:/ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/http/default.rb:95:in `new'
from c:/ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/http/default.rb:95:in `new_request_for'
from c:/ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/http/default.rb:57:in `request'
from c:/ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/http/default.rb:88:in `request'
from c:/ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
from c:/ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/bridge.rb:649:in `raw_execute'
from c:/ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/bridge.rb:123:in `create_session'
from c:/ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/bridge.rb:87:in `initialize'
from c:/ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/firefox/bridge.rb:55:in `initialize'
from c:/ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/common/driver.rb:53:in `new'
from c:/ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/common/driver.rb:53:in `for'
from c:/ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver.rb:84:in `for'
from c:/ruby22/lib/ruby/gems/2.2.0/gems/watir-webdriver-0.9.1/lib/watir-webdriver/browser.rb:46:in `initialize'
from test.rb:3:in `new'
from test.rb:3:in `<main>'
HTTP request path is empty means what? is the calling parameters changed in new versions of watir?
Anyone faced similar problem?
My System is Windows 7 64 bit, I am running behind a proxy, the browser already configured with a proxy
---EDIT---
I have introduced a trailing slash, but I am getting a new error now and also getting the previous error, every time I have to change the code and save it to get this error
c:/ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/firefox/launcher.rb:90:in `connect_until_stable': unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055) (Selenium::WebDriver::Error::WebDriverError)
from c:/ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/firefox/launcher.rb:55:in `block in launch'
from c:/ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/common/socket_lock.rb:43:in `locked'
from c:/ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/firefox/launcher.rb:51:in `launch'
from c:/ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/firefox/bridge.rb:43:in `initialize'
from c:/ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/common/driver.rb:53:in `new'
from c:/ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/common/driver.rb:53:in `for'
from c:/ruby22/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver.rb:84:in `for'
from c:/ruby22/lib/ruby/gems/2.2.0/gems/watir-webdriver-0.9.1/lib/watir-webdriver/browser.rb:46:in `initialize'
from test.rb:8:in `new'
from test.rb:8:in `<main>'
---EDIT---
I have downloaded the geckodriver v0.10.0 from https://github.com/mozilla/geckodriver/releases and copy pasted the geckodriver.exe in to the firefox folder and also added the firefox folder to the PATH
I installed the selenium-webdriver beta version 3.0.0.beta2.1
But still I am getting the same error
c:/ruby22/lib/ruby/2.2.0/net/http/generic_request.rb:25:in `initialize': HTTP request path is empty (ArgumentError)
I have also tried installing the Firefox ESR version and added to PATH which is also not working
---EDIT---
I opened the file c:/ruby22/lib/ruby/2.2.0/net/http/generic_request.rb
and introduced print statement as follows
print "\n"
print uri_or_path
if URI === uri_or_path then
print "\ncoming to if part\n"
#uri = uri_or_path.dup
host = #uri.hostname.dup
host << ":".freeze << #uri.port.to_s if #uri.port != #uri.default_port
#path = uri_or_path.request_uri
raise ArgumentError, "no HTTP request path given" unless #path
else
print "\ncoming to else part\n"
#uri = nil
host = nil
raise ArgumentError, "no HTTP request path given" unless uri_or_path
raise ArgumentError, "HTTP request path is empty" if uri_or_path.empty?
#path = uri_or_path.dup
end
And I got the below output
/session
coming to else part
coming to else part
/shutdown
coming to else part
c:/ruby22/lib/ruby/2.2.0/net/http/generic_request.rb:29:in `initialize': HTTP request path is empty (ArgumentError)
Try entering those commands in IRB, a line at a time. that will make it clearer where the failure is occuring
Your initial error indicated it was failing on line 3,which in your code above is where it tries to create a new instance of a browser object (which also launches firefox, and then tries to connect the browser object to the actual browser). If that's not working it's usually because you are not using a version of webdriver that supports your browser. Perhaps you have a brand new firefox, and need to update webdriver.
Sometimes there is a brief window after a new FF comes out (every 6 weeks) that introduced a breaking change, where we don't have an updated webdriver gem that supports that version.
Most likely you were seeing this due to a bug in Firefox 47.0. You need to update to Firefox 47.0.1 for it to work with Selenium 2.53.4.

Selenium Grid Timeout

The following selenium-client (1.2.18) script times out in our test environment. The script works locally, but not in our test environment. I've only included the bare minimum code necessary to reproduce the timeout (which is why I'm doing a http.post directly).
On the test environment, I've looked at the firefox sessionstore.js and seen the browser is getting to the site, but it seems like it never communicates back to the node.
EDIT: curl 'www.google.com' works from the test environment.
require 'selenium/client'
require 'net/http'
#browser = Selenium::Client::Driver.new(:host => 'localhost',
:port => 4445,
:browser => '*firefox',
:url => 'http://www.google.com/',
:timeout_in_second => 60)
#browser.start_new_browser_session
session_id = #browser.session_id
p "SESSION ID: #{session_id}"
http = Net::HTTP.new('localhost', 4445)
begin
response = http.post('/selenium-server/driver/',"cmd=open&1=landing/summer/index.html&2=true&sessionId=#{session_id}")
p "RESPONSE: #{response}"
ensure
p "CLOSING SESSION..."
#browser.close_current_browser_session
end
Grid hub was started with the following:
selenium-server-standalone-2.25.0.jar -port 4445 -timeout 180 -singleWindow -role hub -browserTimeout 300 -newSessionMaxWaitTimeInSeconds 300 -newSessionWaitTimeout 300 -firefoxProfileTemplate /var/tmp/selenium-grid-start-stop/releases/20130802031034/firefox_profile -trustAllSSLCertificates
Node started with the following:
selenium-server-standalone-2.25.0.jar -role node -port 6666 -hub http://localhost:4445/grid/register -maxSession 1 -firefoxProfileTemplate /var/tmp/selenium-grid-start-stop/releases/20130802031034/firefox_profile -browser browserName=*firefox,seleniumProtocol=Selenium
And running the test script...
$ruby test2.rb
"SESSION ID: 18609e43667a4aa094fe81ef30551b84"
"CLOSING SESSION..."
/usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/protocol.rb:140:in `rescue in rbuf_fill': Timeout::Error (Timeout::Error)
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/protocol.rb:134:in `rbuf_fill'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/protocol.rb:116:in `readuntil'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/protocol.rb:126:in `readline'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:2219:in `read_status_line'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:2208:in `read_new'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:1191:in `transport_request'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:1177:in `request'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:1170:in `block in request'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:627:in `start'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:1168:in `request'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:978:in `post'
Anyone seen this kind of timeout before? The site (google) is obviously up. Perhaps something is misconfigured in the test environment?
I've found the solution. We accidently upgraded the Firefox in our test environment from 10 -> 17.
Our Grid nodes were providing a Firefox prefs.js that did not work with Firefox 17. This allowed the browser to start up and connect to the site successfully, but unable (for whatever reason) to respond back to the node.
The solution was to provide an updated prefs.js that worked for FF 17. We obtained this by running a test without providing the preferences ourselves. This forced Firefox to create a default preferences file we copied and edited.

ERROR: My Regression suite was working before, but after I carried out a gem update and updated Firefox to 13.0 Error is occuring

The error that I keep on receiving when running a regression uite, can someone please shed some light on this. It's driving me crazy.
No connection could be made because the target machine actively
refused it. - connect(2) (Errno::ECONNREFUSED)
C:/Ruby187/lib/ruby/1.8/net/http.rb:560:in initialize'
C:/Ruby187/lib/ruby/1.8/net/http.rb:560:inopen'
C:/Ruby187/lib/ruby/1.8/net/http.rb:560:in connect'
C:/Ruby187/lib/ruby/1.8/timeout.rb:53:intimeout'
C:/Ruby187/lib/ruby/1.8/timeout.rb:101:in timeout'
C:/Ruby187/lib/ruby/1.8/net/http.rb:560:inconnect'
C:/Ruby187/lib/ruby/1.8/net/http.rb:553:in do_start'
C:/Ruby187/lib/ruby/1.8/net/http.rb:542:instart'
C:/Ruby187/lib/ruby/1.8/net/http.rb:1035:in request'
C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.22.2/lib/selenium/webdriver/remote/http/default.rb:76:in
response_for'
C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.22.2/lib/selenium/webdriver/remote/http/default.rb:38:in
request'
C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.22.2/lib/selenium/webdriver/remote/http/common.rb:40:in
call'
C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.22.2/lib/selenium/webdriver/remote/bridge.rb:598:in
raw_execute'
C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.22.2/lib/selenium/webdriver/remote/bridge.rb:576:in
execute'
C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.22.2/lib/selenium/webdriver/remote/bridge.rb:189:in
quit'
C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.22.2/lib/selenium/webdriver/firefox/bridge.rb:43:in
quit'
C:/Ruby187/lib/ruby/gems/1.8/gems/selenium-webdriver-2.22.2/lib/selenium/webdriver/common/driver.rb:166:in
quit'
C:/Ruby187/lib/ruby/gems/1.8/gems/watir-webdriver-0.6.1/lib/watir-webdriver/browser.rb:87:in
close'
Firefox 13 requires selenium-webdriver >= 2.23.0. Update it and it'll work correctly.

Patching classes in Ruby's core lib

I'm trying to set the timeout for subsequent http calls to a very unreliable API. I tried multiple attempts at using Ruby's built-in Timeout.timeout() method but had had no such luck getting it to extend to sub calls. For example, Timeout.timeout(300) will set the first timeout to 300 but sub calls go back to 60. I added a print of the seconds_delay and here is what I saw:
[16:55:16 miker#laughwhat-lm ~/optisol/src/rails/tools_app/trunk/adhoc/ticket] $ bundle exec ruby buck.rb
300
nil
warning: peer certificate won't be verified in this SSL session
60
60
nil
warning: peer certificate won't be verified in this SSL session
60
Here is the error I receive with full stack trace:
[16:49:50 miker#laughwhat-lm ~/optisol/src/rails/tools_app/trunk/adhoc/ticket] $ bundle exec ruby buck.rb
warning: peer certificate won't be verified in this SSL session
warning: peer certificate won't be verified in this SSL session
warning: peer certificate won't be verified in this SSL session
warning: peer certificate won't be verified in this SSL session
warning: peer certificate won't be verified in this SSL session
warning: peer certificate won't be verified in this SSL session
warning: peer certificate won't be verified in this SSL session
/Users/miker/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/timeout.rb:64:in `rbuf_fill': execution expired (Timeout::Error)
from /Users/miker/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/net/protocol.rb:134:in `rbuf_fill'
from /Users/miker/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
from /Users/miker/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/net/protocol.rb:126:in `readline'
from /Users/miker/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:2028:in `read_status_line'
from /Users/miker/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:2017:in `read_new'
from /Users/miker/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:1051:in `request_without_fakeweb'
from /Users/miker/.rvm/gems/ree-1.8.7-2011.03/gems/fakeweb-1.3.0/lib/fake_web/ext/net_http.rb:50:in `request'
from /Users/miker/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:845:in `post'
from /Users/miker/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/soap/netHttpClient.rb:93:in `post'
from /Users/miker/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/soap/netHttpClient.rb:116:in `start'
from /Users/miker/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:543:in `start'
from /Users/miker/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/soap/netHttpClient.rb:115:in `start'
from /Users/miker/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/soap/netHttpClient.rb:92:in `post'
from /Users/miker/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/soap/streamHandler.rb:170:in `send_post'
from /Users/miker/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/soap/streamHandler.rb:109:in `send'
from /Users/miker/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/soap/rpc/proxy.rb:170:in `route'
from /Users/miker/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/soap/rpc/proxy.rb:141:in `call'
from /Users/miker/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/soap/rpc/driver.rb:178:in `call'
from /Users/miker/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/soap/rpc/driver.rb:232:in `getByBuyer'
from buck.rb:9
from /Users/miker/.rvm/gems/ree-1.8.7-2011.03/gems/yieldmanager-0.8.2/lib/yieldmanager/client.rb:131:in `session'
from buck.rb:8
from /Users/miker/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/timeout.rb:67:in `timeout'
from /Users/miker/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/timeout.rb:101:in `timeout'
from buck.rb:6
So I guess my question would be how can I go about patching the protocol.rb BufferedIO's method to look like this:
class BufferedIO
private
def rbuf_fill
puts "working"
timeout(300) { # forced 300 second timeout
#rbuf << #io.sysread(BUFSIZE)
}
end
end
Adding that to my ruby file before or after I do my requires/includes does not have an affect (i.e. no "working" is ever printed out). Hope someone has a solution. Thanks!
Of all the various Ruby library's, the clumsiest to work with and ugliest, in my opinion, would have to be net::http. Have you considered switching to something like this:
https://github.com/dbalatero/typhoeus
The requests in typhoeus occur via lib-curl and so aren't bound by Ruby's not-so-reliable when nested or threaded timeout method.
In terms of the rbuf_fill issue, I'm not sure if that will get you there. If I remember correctly, when a timeout exception fires, it always shows the location that the code is currently at in the stack. That location is only incidental. Take the example below I just ran in irb. Notice how it tells you the timeout occured in "sleep"? Where the timeout is reported is just what it happened to be doing at that moment, not where the timeout code is necessarily implemented, nor do you know which timeout it is that is tripping if there are multiple. I'd have to chase down the rbuf_fill to confirm this for you though, and I have to run at the moment...
irb> timeout(2){sleep 5}
Timeout::Error: execution expired
from (irb):3:in sleep'
from (irb):3:inblock in irb_binding'
from (irb):3
from /home/ebelan

Ruby networking problem on windows

I am running windows XP with ruby 1.8.6 patchlevel 111. I am using HTTP to connect to a remote server and it has been running fine. All of a sudden it started to through the exception listed below (I did not change any code since the last time I ran it successfully). Does anybody know what is going on?
c:/ruby/lib/ruby/1.8/timeout.rb:54:in `rbuf_fill': execution expired (Timeout::E
rror)
from c:/ruby/lib/ruby/1.8/timeout.rb:56:in `timeout'
from c:/ruby/lib/ruby/1.8/timeout.rb:76:in `timeout'
from c:/ruby/lib/ruby/1.8/net/protocol.rb:132:in `rbuf_fill'
from c:/ruby/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
from c:/ruby/lib/ruby/1.8/net/protocol.rb:126:in `readline'
from c:/ruby/lib/ruby/1.8/net/http.rb:2029:in `read_status_line'
from c:/ruby/lib/ruby/1.8/net/http.rb:2018:in `read_new'
from c:/ruby/lib/ruby/1.8/net/http.rb:1059:in `request'
... 19 levels...
from c:/ruby/lib/ruby/1.8/test/unit/autorunner.rb:216:in `run'
from c:/ruby/lib/ruby/1.8/test/unit/autorunner.rb:12:in `run'
from c:/ruby/lib/ruby/1.8/test/unit.rb:278
from c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader
.rb:5
rake aborted!
Command failed with status (3): [c:/ruby/bin/ruby -Ilib;test "c:/ruby/lib/r...]
Maybe the remote host is down? Or a new firewall has been put between your machine and the remote host?
"Timeout::Error" usually points to that direction.
besides the obvious (firewall, you got blacklisted for bad user-agent or ignoring robots.txt), you can try curl
http://curl.haxx.se/libcurl/ruby/
OR increase net/http timeout to say, 30+ seconds
http://groups.google.com/group/rubyonrails-talk/msg/cc89e8ae6703d6fb
It could be related to this known Ruby bug where Timeout::Error does not subclass Exception. (fixed in 1.9.2 I believe)
http://lindsaar.net/2007/12/9/rbuf_filltimeout-error
It can be fixed by rescuing from Timeout::Error like rescue Timeout::Error => e

Resources