Mandrill-api Excon :: Errors :: SocketError

Jim*_*Chu 5 ruby ruby-on-rails-3 mandrill excon

我在Ruby中使用Mandrill-api以编程方式发送交易电子邮件.

我在rails应用程序中有(或多或少)以下行,

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

问题是在生产中运行时,偶尔会返回以下错误.

Excon::Errors::SocketError (EOFError (EOFError)):
app/mailers/mailer.rb:24:in `send'
....
Run Code Online (Sandbox Code Playgroud)

我不知道如何调试此问题.如果有人能让我了解调试方法,我非常感谢.

宝石信息:

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

生产环境:

 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
Run Code Online (Sandbox Code Playgroud)

运行:

Apache服务器:Apache/2.2.22(Ubuntu)

乘客:3.0.14

gee*_*mus 3

这很可能是套接字超时。Excon 尝试在可能的情况下使用持久连接,但不幸的是,有时这会反过来咬我们一口。看来 mandrill-api 正在尝试在其调用方法中重用相同的连接/套接字:https://bitbucket.org/mailchimp/mandrill-api-ruby/src/03e3e28e77dcba31eab7d2f9e2216b5a01d2110d/lib/mandrill.rb ?at=master# CL-35

这通常应该没问题,但如果给定会话的生存时间较长(即,猜测可能超过 30 秒),则可能会导致您在上面看到的行为。在 excon 连接上调用 #reset 将确保您不会遇到这种情况,因此这可能是最安全的方法(尽管这会阻止使用持久连接,因此如果您执行大量请求,性能将会受到影响) )。

我希望这会有所帮助,也许我们应该与 mandrill-api 讨论更新这个问题。考虑到所涉及的性能影响,可能只取决于问题的间歇性(或非间歇性)。希望有帮助,但我当然很乐意尽我所能讨论/提供帮助。