Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mandrill-api Excon::Errors::SocketError

I am using Mandrill-api in Ruby to programmatically send out transactional email.

I have (more or less) the following line in my rails app,

mandrill ||= Mandrill::API.new const(:API)[:MANDRILL_APIKEY]
... (constructing the message, content, etc)
mandrill.messages.send_template templ, template_content, message, true

The problem is when running in production, it returns the following error once in a while.

Excon::Errors::SocketError (EOFError (EOFError)):
app/mailers/mailer.rb:24:in `send'
....

I have no idea how to debug this issue. If somebody could shed me light on the approach for debugging this, I highly appreciate it.

Gems Info:

  • mandrill-api (1.0.33)
  • excon (0.16.10)

Production env:

 sudo bundle exec rake RAILS_ENV=production about


About your application's environment
Ruby version              1.9.3 (x86_64-linux)
RubyGems version          1.8.11
Rack version              1.4
Rails version             3.2.13
Active Record version     3.2.13
Action Pack version       3.2.13
Active Resource version   3.2.13
Action Mailer version     3.2.13
Active Support version    3.2.13
Middleware                Rack::Cache, Rack::Lock, #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x00000001e72330>, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Callbacks, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, ActionDispatch::Head, Rack::ConditionalGet, Rack::ETag, ActionDispatch::BestStandardsSupport
Environment               production
Database adapter          mysql2

Running on:

Apache Server: Apache/2.2.22 (Ubuntu)

Passenger: 3.0.14

like image 228
Jimmy Chu Avatar asked Oct 21 '22 04:10

Jimmy Chu


1 Answers

It is most likely a socket timeout. Excon tries to use persistent connections when it can, but sometimes this comes back to bite us unfortunately. It appears that mandrill-api is attempting to reuse the same connection/socket in it's call method: https://bitbucket.org/mailchimp/mandrill-api-ruby/src/03e3e28e77dcba31eab7d2f9e2216b5a01d2110d/lib/mandrill.rb?at=master#cl-35

That should normally be fine, but might lead to the behavior you are seeing above if a given session lives for a longer time (ie probably greater than 30 seconds, at a guess). Calling #reset on the excon connection would ensure that you wouldn't encounter this, so that is probably the safest way (though this prevents persistent connections from being used, so there would be a small performance hit if you are doing a lot of requests).

I hope that helps, perhaps we should discuss with mandrill-api about updating this. Might just depend how intermittent (or not) the issue is, given the performance hit involved. Hope that helps, but certainly happy to discuss/help out however I can.

like image 161
geemus Avatar answered Oct 24 '22 05:10

geemus