chicks / sugarcrm

A ruby based REST Client for SugarCRM
MIT License
90 stars 64 forks source link

#<Errno::EPIPE: Broken pipe> #63

Closed m-burhan closed 13 years ago

m-burhan commented 13 years ago

Hi -

I am using below code to confirm existence of a contact from sugarcrm when contact's email is matched

sc_contacts = SugarCRM.connection.get_entry_list( "Contacts", "contacts.id IN (SELECT bean_id FROM email_addr_bean_rel eabr JOIN email_addresses ea ON (eabr.email_address_id = ea.id) WHERE bean_module = 'Contacts' AND ea.email_address_caps LIKE '#{subscriber_info["email"].upcase}' AND eabr.deleted=0)" )

at this line of code below exception is raised, any thoughts on it?

/usr/local/lib/ruby/1.9.1/net/protocol.rb:191:in write' /usr/local/lib/ruby/1.9.1/net/protocol.rb:191:inwrite0' /usr/local/lib/ruby/1.9.1/net/protocol.rb:167:in block in write' /usr/local/lib/ruby/1.9.1/net/protocol.rb:182:inwriting' /usr/local/lib/ruby/1.9.1/net/protocol.rb:166:in write' /usr/local/lib/ruby/1.9.1/net/http.rb:1739:insend_request_with_body' /usr/local/lib/ruby/1.9.1/net/http.rb:1724:in exec' /usr/local/lib/ruby/1.9.1/net/http.rb:1189:intransport_request' /usr/local/lib/ruby/1.9.1/net/http.rb:1177:in request' /usr/local/lib/ruby/1.9.1/net/http.rb:978:inpost' /usr/local/lib/ruby/gems/1.9.1/gems/sugarcrm-0.9.15/lib/sugarcrm/connection/connection.rb:75:in send!' /usr/local/lib/ruby/gems/1.9.1/gems/sugarcrm-0.9.15/lib/sugarcrm/connection/api/get_entry_list.rb:29:inget_entry_list' /var/www/sync_contacts/service/sync_contacts.rb:572:in block in get_sugar_contact' /var/www/sync_contacts/service/sync_contacts.rb:570:ineach' /var/www/sync_contacts/service/sync_contacts.rb:570:in get_sugar_contact' /var/www/sync_contacts/service/service.rb:138:inblock in class:Service' /usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:1152:in call' /usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:1152:inblock in compile!' /usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:724:in instance_eval' /usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:724:inroute_eval' /usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:708:in block (2 levels) in route!' /usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:758:inblock in process_route' /usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:755:in catch' /usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:755:inprocess_route' /usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:707:in block in route!' /usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:706:ineach' /usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:706:in route!' /usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:843:indispatch!' /usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:644:in block in call!' /usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:808:ininstance_eval' /usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:808:in block in invoke' /usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:808:incatch' /usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:808:in invoke' /usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:644:incall!' /usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:629:in call' /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.3.1/lib/rack/head.rb:9:incall' /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.3.1/lib/rack/commonlogger.rb:20:in call' /usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/showexceptions.rb:21:incall' /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.3.1/lib/rack/methodoverride.rb:24:in call' /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.3.1/lib/rack/showexceptions.rb:24:incall' /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.3.1/lib/rack/lint.rb:48:in _call' /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.3.1/lib/rack/lint.rb:36:incall' /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.3.1/lib/rack/showexceptions.rb:24:in call' /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.3.1/lib/rack/commonlogger.rb:20:incall' /usr/local/lib/ruby/gems/1.9.1/gems/unicorn-4.0.1/lib/unicorn/http_server.rb:518:in process_client' /usr/local/lib/ruby/gems/1.9.1/gems/unicorn-4.0.1/lib/unicorn/http_server.rb:585:inworker_loop' /usr/local/lib/ruby/gems/1.9.1/gems/unicorn-4.0.1/lib/unicorn/http_server.rb:475:in spawn_missing_workers' /usr/local/lib/ruby/gems/1.9.1/gems/unicorn-4.0.1/lib/unicorn/http_server.rb:135:instart' /usr/local/lib/ruby/gems/1.9.1/gems/unicorn-4.0.1/bin/unicorn:121:in `<top (required)>'

chicks commented 13 years ago

Based on the exception, the connection is going away before it finishes sending the request.

Does this happen every time, or intermittently?

muhammadburhan commented 13 years ago

that happens sporadically.

chicks commented 13 years ago

I think we just need to catch this exception and retry (in https://github.com/chicks/sugarcrm/blob/master/lib/sugarcrm/connection/connection.rb)

I'll try to patch and test/release this this weekend.

sultan-bhatia commented 13 years ago

I'm getting the same error. Any time line on the fix?

chicks commented 13 years ago

Fixed. Can you update to 0.9.16 and let me know if you run into any additional issues?

sultan-bhatia commented 13 years ago

This is what happened once:

Exiting /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/bundler/gems/sugarcrm-ee48a4d4c53d/lib/sugarcrm/connection/connection.rb:75:in send!': SugarCRM::Connection Errors: (SugarCRM::RetryLimitExceeded) execution expired execution expired execution expired from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/bundler/gems/sugarcrm-ee48a4d4c53d/lib/sugarcrm/connection/connection.rb:89:insend!' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/bundler/gems/sugarcrm-ee48a4d4c53d/lib/sugarcrm/connection/api/login.rb:16:in login' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/bundler/gems/sugarcrm-ee48a4d4c53d/lib/sugarcrm/connection/connection.rb:45:inlogin!' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/bundler/gems/sugarcrm-ee48a4d4c53d/lib/sugarcrm/connection/connection.rb:33:in initialize' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/bundler/gems/sugarcrm-ee48a4d4c53d/lib/sugarcrm/connection_pool.rb:115:innew' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/bundler/gems/sugarcrm-ee48a4d4c53d/lib/sugarcrm/connection_pool.rb:115:in new_connection' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/bundler/gems/sugarcrm-ee48a4d4c53d/lib/sugarcrm/connection_pool.rb:121:incheckout_new_connection' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/bundler/gems/sugarcrm-ee48a4d4c53d/lib/sugarcrm/connection_pool.rb:61:in checkout' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/bundler/gems/sugarcrm-ee48a4d4c53d/lib/sugarcrm/connection_pool.rb:57:inloop' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/bundler/gems/sugarcrm-ee48a4d4c53d/lib/sugarcrm/connection_pool.rb:57:in checkout' from /Users/sultanbhatia/.rvm/rubies/ruby-1.8.7-p174/lib/ruby/1.8/monitor.rb:242:insynchronize' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/bundler/gems/sugarcrm-ee48a4d4c53d/lib/sugarcrm/connection_pool.rb:56:in checkout' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/bundler/gems/sugarcrm-ee48a4d4c53d/lib/sugarcrm/connection_pool.rb:41:inconnection' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/bundler/gems/sugarcrm-ee48a4d4c53d/lib/sugarcrm/session.rb:95:in connection' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/bundler/gems/sugarcrm-ee48a4d4c53d/lib/sugarcrm/module.rb:138:inregister_all' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/bundler/gems/sugarcrm-ee48a4d4c53d/lib/sugarcrm/session.rb:68:in connect' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/bundler/gems/sugarcrm-ee48a4d4c53d/lib/sugarcrm/session.rb:19:ininitialize' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/bundler/gems/sugarcrm-ee48a4d4c53d/lib/sugarcrm/session.rb:35:in new' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/bundler/gems/sugarcrm-ee48a4d4c53d/lib/sugarcrm/session.rb:35:infrom_hash' from /Users/sultanbhatia/mobisoft/config/initializers/sugarcrm.rb:5 from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:in load' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:inload' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in load_dependency' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:591:innew_constants_in' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in load_dependency' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:inload' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/gems/railties-3.0.0/lib/rails/engine.rb:201 from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/gems/railties-3.0.0/lib/rails/engine.rb:200:in each' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/gems/railties-3.0.0/lib/rails/engine.rb:200 from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/gems/railties-3.0.0/lib/rails/initializable.rb:25:ininstance_exec' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/gems/railties-3.0.0/lib/rails/initializable.rb:25:in run' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/gems/railties-3.0.0/lib/rails/initializable.rb:50:inrun_initializers' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/gems/railties-3.0.0/lib/rails/initializable.rb:49:in each' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/gems/railties-3.0.0/lib/rails/initializable.rb:49:inrun_initializers' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/gems/railties-3.0.0/lib/rails/application.rb:134:in initialize!' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/gems/railties-3.0.0/lib/rails/application.rb:77:insend' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/gems/railties-3.0.0/lib/rails/application.rb:77:in method_missing' from /Users/sultanbhatia/mobisoft/config/environment.rb:5 from /Users/sultanbhatia/mobisoft/config.ru:3:inrequire' from /Users/sultanbhatia/mobisoft/config.ru:3 from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/gems/rack-1.2.3/lib/rack/builder.rb:46:in instance_eval' from /Users/sultanbhatia/.rvm/gems/ruby-1.8.7-p174@mobisoft-r187p174r300/gems/rack-1.2.3/lib/rack/builder.rb:46:ininitialize' from /Users/sultanbhatia/mobisoft/config.ru:1:in `new' from /Users/sultanbhatia/mobisoft/config.ru:1

chicks commented 13 years ago

That means the gem tried to send the request three times and failed. Each failure is an "execution expired" error, which indicates the server took too long to respond (according to the client). You can adjust how long the gem will wait before throwing this error with:

SugarCRM.connection.connection.read_timeout 

You also might consider structuring your API calls so that they return faster, or handle smaller amounts of data.

sultan-bhatia commented 13 years ago

Setting SugarCRM.connection.connection.read_timeout seems to have solved the problem. Thanks.

chicks commented 13 years ago

Awesome!