5

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

geemus
  • 2,522
  • 16
  • 22
Jimmy Chu
  • 972
  • 8
  • 27
  • It would be a lot easier to help if you can provide some information about your production environment. – Tyler Jul 21 '13 at 16:11
  • tyler, added production env. Let me know if there is additional specific piece of info to help debugging. Thanks. – Jimmy Chu Jul 22 '13 at 03:56

2 Answers2

3

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.

geemus
  • 2,522
  • 16
  • 22
0

It could have something to do with keeping the socket open beyond its expiration, given that it's an EOF error and is intermittent.

Are there any settings for opening a new socket with each request, rather than reusing the same one?

Tyler
  • 11,272
  • 9
  • 65
  • 105
  • 3
    Why is this checked as the answer? It provides a potential direction for searching but it's just a question (and would be better as a comment to the original post, IMO). I'm getting the same error too – intermittently – and would love to see an answer as well. – davemyron Aug 13 '13 at 20:17
  • @orangechicken, did you ever figure out what was causing this? – Peter Berg Nov 15 '13 at 20:46
  • @Accipheran: I don't believe I did. I've upgraded away from the version I was using then and don't think I've noticed problems since (but that could just be a visibility issue). – davemyron Nov 18 '13 at 12:09