Getting elasticsearch connect error on continuous uploads - ruby

I have a script that reads lines one by one from a csv file and index the same to elasticsearch in the same order. My elasticsearch host is the same machine on which the script is running. Everything else works fine except for a few rows when I suddenly start getting the following error:
W, [2012-10-09T14:46:00.899876 #11567] WARN -- : Cannot assign requested address connect(2)
D, [2012-10-09T14:46:00.900037 #11567] DEBUG -- : ["/home/azitabh/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/net/http.rb:644:in `initialize'", "/home/azitabh/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/net/http.rb:644:in `open'", "/home/azitabh/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/net/http.rb:644:in `block in connect'", "/home/azitabh/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/timeout.rb:44:in `timeout'", "/home/azitabh/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/timeout.rb:89:in `timeout'", "/home/azitabh/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/net/http.rb:644:in `connect'", "/home/azitabh/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/net/http.rb:637:in `do_start'", "/home/azitabh/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/net/http.rb:626:in `start'", "/home/azitabh/.rvm/gems/ruby-1.9.2-p320/gems/rest-client-1.6.7/lib/restclient/request.rb:172:in `transmit'", "/home/azitabh/.rvm/gems/ruby-1.9.2-p320/gems/rest-client-1.6.7/lib/restclient/request.rb:64:in `execute'", "/home/azitabh/.rvm/gems/ruby-1.9.2-p320/gems/tire-0.4.2/lib/tire/http/client.rb:11:in `get'", "/home/azitabh/.rvm/gems/ruby-1.9.2-p320/gems/tire-0.4.2/lib/tire/search.rb:94:in `perform'", "/home/azitabh/.rvm/gems/ruby-1.9.2-p320/gems/tire-0.4.2/lib/tire/search.rb:20:in `results'", "models/test.rb:31:in `get_details'", "models/test.rb:56:in `block in index_test'", "/home/azitabh/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/csv.rb:1768:in `each'", "/home/azitabh/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/csv.rb:1202:in `block in foreach'", "/home/azitabh/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/csv.rb:1340:in `open'", "/home/azitabh/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/csv.rb:1201:in `foreach'", "models/test.rb:40:in `index_test'", "models/test.rb:85:in `<main>'"]
And the errors are not related to the values at those rows in the csv. I get these errors at different locations at different times.
There is another error "WAIT_TIMEOUT" which I get some time. Couldn't put the trace here as I didn't get that error this time.
I am coding in ruby and using "Tire" gem to talk to elasticsearch. I don't feel these are responsible in any way though.
JAVA was using 8% of my system's memory at the time I got this error. This is much below the assigned value ES_MIN_MEM=2g.
Thanks in advance
-Azitabh

This is happening because tire doesn't close the tcp connection by itself. Once all the available ports gets engaged, no further connection is possible until system closes all connections in waiting state itself. This takes some time and any attempt to establish new connection results in wait_timeout.

Related

ECONNRESET error when accessing Ruby application which runs in Webrick

I am trying to install redmine (bugtracker which runs on ruby). I use webrick, it starts all fine, but when I access http://IP:3000/, it throws the following error in the server logs and the page does not load in the browser.
ERROR Errno::ECONNRESET: Connection reset by peer # io_fillbuf - fd:11
/root/.rbenv/versions/2.5.1/lib/ruby/2.5.0/webrick/httpserver.rb:82:in `eof?'
/root/.rbenv/versions/2.5.1/lib/ruby/2.5.0/webrick/httpserver.rb:82:in `run'
/root/.rbenv/versions/2.5.1/lib/ruby/2.5.0/webrick/server.rb:307:in `block in start_thread'
I am a bit stuck here, any help would be greatly appreciated.
Thanks in advance.
In the end, it was due to the port 3000 was being blocked by the network where the server was part of. Once the port block was removed, it started to work. Thanks #mike-k for your tips.

RallyRestToolkitForRuby - Unable to pull user permissions

Am trying to use https://github.com/RallyTools/RallyRestToolkitForRuby to pull permissions of all users in my Rally Subscription. My authentication is through API Key. It fails with below error:
C:\Users\Administrator\Desktop\Rally-User-Management-master\Rally-User-Management-master>user_permissions_summary.rb
Connecting to Rally: https://rally1.rallydev.com/slm as ganra08#ca.com...
Running initial query of users...
Found a total of 12392 Enabled Users.
Summarizing users and writing permission summary output file...
C:/Users/Administrator/Desktop/Rally-User-Management-master/Rally-User-Management-master/lib/go_user_permissions_summary.rb:224:in block (2 levels) in go_user_permissions_summary'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rally_api-1.2.1/lib/rally_api/rally_colle
ction.rb:36:ineach'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rally_api-1.2.1/lib/rally_api/rally_collection.rb:36:in each'
C:/Users/Administrator/Desktop/Rally-User-Management-master/Rally-User-Management-master/lib/go_user_permissions_summary.rb:201:inblock in go_user_permissions_summary'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rally_api-1.2.1/lib/rally_api/rally_query_result.rb:22:in block in each'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rally_api-1.2.1/lib/rally_api/rally_query_result.rb:21:ineach'
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rally_api-1.2.1/lib/rally_api/rally_query_result.rb:21:in each'
C:/Users/Administrator/Desktop/Rally-User-Management-master/Rally-User-Management-master/lib/go_user_permissions_summary.rb:180:ingo_user_permissions_summary'
C:/Users/Administrator/Desktop/Rally-User-Management-master/Rally-User-Management-master/user_permissions_summary.rb:38:in <main>' undefined method[]' for nil:NilClass
How do i get over this error? The Readme.pdf in the GitHub page provides no info about this.
Agile Central (formerly Rally) support helped to resolve this.
The $wsapi_version variable is set in a couple of places. We need to ensure that it is set to '1.43', and not 'v2.0'. Then the error went away and the script runs as expected.
If using the my_vars.rb file, comment out both lines of the $wsapi_version and just let the one in the go_user_permissions_summary.rb (1.43) be used.

setting response timeout in ruby XMLRPC not working

I am trying to programmatically upload a large-sized (10+ MB) file to a server that supports XMLRPC.
For those interested, the background is:
The server is Confluence.
I am trying to upload a file as attachment to a Confluence page.
I am using the Confluence XMLRPC API. The API call is addAttachment.
The code looks something like this
require 'xmlrpc/client'
server = XMLRPC::Client.new2(server_url,"",600) # one attempt to set timeout
server.instance_variable_get(:#http).instance_variable_set(:#verify_mode, OpenSSL::SSL::VERIFY_NONE)
server.timeout=6000 # another attempt to set timeout
#conf = server.proxy("confluence2")
I know that the XMLRPC client will wait for TIMEOUT seconds before it aborts. So its natural that I got the following response when trying to upload the large file (smaller files don't throw this error).
C:/Ruby193/lib/ruby/1.9.1/openssl/buffering.rb:318:in `syswrite': An established connection was aborted by the software
in your host machine. (Errno::ECONNABORTED)
from C:/Ruby193/lib/ruby/1.9.1/openssl/buffering.rb:318:in `do_write'
from C:/Ruby193/lib/ruby/1.9.1/openssl/buffering.rb:336:in `write'
from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:199:in `write0'
from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:173:in `block in write'
from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:190:in `writing'
from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:172:in `write'
from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1938:in `send_request_with_body'
from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1920:in `exec'
However, I am unable to properly set the response timeout. I have tried
server.timeout
the timeout parameter in the new2 call
Neither of which work. I have verified that the client still waits the default 30 seconds for the response, and then throws the error.
So, what am I doing wrong?

Why ruby process starts getting: "getaddrinfo: Temporary failure in name resolution" on all remote calls before restart

I have a couple of dedicated servers where I have background workers running for days sometimes before restart. When this happens (that they run for more than 24 hours it seems) then I start to get errors like this:
getaddrinfo: Temporary failure in name resolution
/home/deployer/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/smtp.rb:540:in `open'
/home/deployer/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/smtp.rb:540:in `tcp_socket'
/home/deployer/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/smtp.rb:549:in `block in do_start'
/home/deployer/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/timeout.rb:68:in `timeout'
/home/deployer/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
/home/deployer/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/smtp.rb:549:in `do_start'
/home/deployer/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/smtp.rb:519:in `start'
The error will occur for ALL remote calls from that specific process, until it has been restarted (NOT hardware/server restart, just the ruby process). I have double-checked/confirmed that restarting the process works as a fix, since I have tried to SSH into the server, and run a new process along side the failing one, and this one would work flawlessly, while the faulty one still failed.
So my question is, why is this happening, and how can I resolve the issue in an other way than restarting the process every day?
I am on ruby 1.9.3 p194 and the background jobs are processed with the sidekiq gem (however I don't suspect that one to be responsible for the mess).
The servers are situated at http://www.hetzner.de (however I don't think they are to blame, since it's happening in-process)
UPDATE
Along side the above smtp call errors, I'm also getting errors like this, when doing simple http requests. This also resolves after a process restart:
# (Errno::EHOSTUNREACH) "No route to host - connect(2)"
/home/deployer/apps/au/shared/bundle/ruby/1.9.1/gems/net-http-persistent-2.8/lib/net/http/persistent/ssl_reuse.rb:29:in `initialize'
/home/deployer/apps/au/shared/bundle/ruby/1.9.1/gems/net-http-persistent-2.8/lib/net/http/persistent/ssl_reuse.rb:29:in `open'
/home/deployer/apps/au/shared/bundle/ruby/1.9.1/gems/net-http-persistent-2.8/lib/net/http/persistent/ssl_reuse.rb:29:in `block in connect'
/home/deployer/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/timeout.rb:54:in `timeout'
/home/deployer/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
/home/deployer/apps/au/shared/bundle/ruby/1.9.1/gems/net-http-persistent-2.8/lib/net/http/persistent/ssl_reuse.rb:29:in `connect'
/home/deployer/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
/home/deployer/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:750:in `start'
/home/deployer/apps/au/shared/bundle/ruby/1.9.1/gems/net-http-persistent-2.8/lib/net/http/persistent.rb:628:in `start'
/home/deployer/apps/au/shared/bundle/ruby/1.9.1/gems/net-http-persistent-2.8/lib/net/http/persistent.rb:888:in `reset'
/home/deployer/apps/au/shared/bundle/ruby/1.9.1/gems/net-http-persistent-2.8/lib/net/http/persistent.rb:567:in `connection_for'
/home/deployer/apps/au/shared/bundle/ruby/1.9.1/gems/net-http-persistent-2.8/lib/net/http/persistent.rb:926:in `request'
/home/deployer/apps/au/shared/bundle/ruby/1.9.1/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:258:in `fetch'
/home/deployer/apps/au/shared/bundle/ruby/1.9.1/gems/mechanize-2.5.1/lib/mechanize.rb:407:in `get'

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