异步发送邮件时的“SSL_read:证书已在哈希表中”
Posted
技术标签:
【中文标题】异步发送邮件时的“SSL_read:证书已在哈希表中”【英文标题】:"SSL_read: cert already in hash table" when sending mail asynchronously 【发布时间】:2014-04-08 05:37:39 【问题描述】:使用 ActionMailer 异步发送延迟电子邮件时,我不断收到带有 SSL_read: cert already in hash table
消息的 OpenSSL::SSL::SSLError
。
我们使用 Sidekiq 异步发送所有电子邮件。在 Sidekiq GitHub 存储库中将此问题作为问题提出时,我被告知 Sidekiq 对 SSL 连接一无所知或管理。
我们的应用托管在 Heroku 上,运行 OpenSSL 0.9.8k 25 Mar 2009
。
我们在其他作业中多次看到此错误,并发现有时作业会得到处理,但有时不会。
这是多个 Sidekiq 线程尝试使用同一个 SSL 连接的 OpenSSL 线程问题吗?有解决办法吗?
这是我们得到的堆栈跟踪:
[PROJECT_ROOT]/vendor/ruby-2.0.0/lib/ruby/2.0.0/openssl/buffering.rb:175:in `sysread_nonblock`
[PROJECT_ROOT]/vendor/ruby-2.0.0/lib/ruby/2.0.0/openssl/buffering.rb:175:in `read_nonblock`
[PROJECT_ROOT]/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/protocol.rb:153:in `rbuf_fill`
[PROJECT_ROOT]/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/protocol.rb:134:in `readuntil`
[PROJECT_ROOT]/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/protocol.rb:144:in `readline`
[PROJECT_ROOT]/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:932:in `recv_response`
[PROJECT_ROOT]/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:903:in `block in data`
[PROJECT_ROOT]/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:942:in `critical`
[PROJECT_ROOT]/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:896:in `data`
[PROJECT_ROOT]/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:663:in `block in send_message`
[PROJECT_ROOT]/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:852:in `rcptto_list`
[PROJECT_ROOT]/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:663:in `send_message`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/mail-2.5.4/lib/mail/network/delivery_methods/smtp.rb:113:in `block in deliver!`
[PROJECT_ROOT]/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:521:in `start`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/mail-2.5.4/lib/mail/network/delivery_methods/smtp.rb:112:in `deliver!`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/mail-2.5.4/lib/mail/message.rb:2129:in `do_delivery`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/mail-2.5.4/lib/mail/message.rb:232:in `block in deliver`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/actionmailer-4.0.3/lib/action_mailer/base.rb:456:in `block in deliver_mail`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/notifications.rb:159:in `block in instrument`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/notifications.rb:159:in `instrument`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/actionmailer-4.0.3/lib/action_mailer/base.rb:454:in `deliver_mail`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/mail-2.5.4/lib/mail/message.rb:232:in `deliver`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-2.17.2/lib/sidekiq/extensions/action_mailer.rb:20:in `perform`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-2.17.2/lib/sidekiq/processor.rb:49:in `block (3 levels) in process`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-2.17.2/lib/sidekiq/middleware/chain.rb:122:in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-2.17.2/lib/sidekiq/middleware/chain.rb:122:in `block in invoke`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.7.1.182/lib/new_relic/agent/instrumentation/sidekiq.rb:30:in `block in call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.7.1.182/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:339:in `perform_action_with_newrelic_trace`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.7.1.182/lib/new_relic/agent/instrumentation/sidekiq.rb:21:in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-2.17.2/lib/sidekiq/middleware/chain.rb:124:in `block in invoke`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-failures-0.3.0/lib/sidekiq/failures/middleware.rb:10:in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-2.17.2/lib/sidekiq/middleware/chain.rb:124:in `block in invoke`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-unique-jobs-2.7.0/lib/sidekiq-unique-jobs/middleware/server/unique_jobs.rb:15:in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-2.17.2/lib/sidekiq/middleware/chain.rb:124:in `block in invoke`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-2.17.2/lib/sidekiq/middleware/server/active_record.rb:6:in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-2.17.2/lib/sidekiq/middleware/chain.rb:124:in `block in invoke`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-2.17.2/lib/sidekiq/middleware/server/retry_jobs.rb:62:in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-2.17.2/lib/sidekiq/middleware/chain.rb:124:in `block in invoke`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-2.17.2/lib/sidekiq/middleware/server/logging.rb:11:in `block in call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-2.17.2/lib/sidekiq/logging.rb:22:in `with_context`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-2.17.2/lib/sidekiq/middleware/server/logging.rb:7:in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-2.17.2/lib/sidekiq/middleware/chain.rb:124:in `block in invoke`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-2.17.2/lib/sidekiq/middleware/chain.rb:127:in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-2.17.2/lib/sidekiq/middleware/chain.rb:127:in `invoke`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-2.17.2/lib/sidekiq/processor.rb:48:in `block (2 levels) in process`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-2.17.2/lib/sidekiq/processor.rb:105:in `stats`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-2.17.2/lib/sidekiq/processor.rb:47:in `block in process`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-2.17.2/lib/sidekiq/processor.rb:86:in `do_defer`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/sidekiq-2.17.2/lib/sidekiq/processor.rb:37:in `process`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/celluloid-0.15.2/lib/celluloid/calls.rb:25:in `public_send`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/celluloid-0.15.2/lib/celluloid/calls.rb:25:in `dispatch`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/celluloid-0.15.2/lib/celluloid/calls.rb:122:in `dispatch`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/celluloid-0.15.2/lib/celluloid/actor.rb:322:in `block in handle_message`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/celluloid-0.15.2/lib/celluloid/actor.rb:416:in `block in task`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/celluloid-0.15.2/lib/celluloid/tasks.rb:55:in `block in initialize`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/celluloid-0.15.2/lib/celluloid/tasks/task_fiber.rb:13:in `block in create
【问题讨论】:
为什么 Heroku 从 2009 年开始运行 OpenSSL?太可怕了。 在堆栈跟踪中看不到错误。跟踪是否完整? 我刚跑了heroku run bash --remote production
,然后跑openssl version
,看看OpenSSL 1.0.1f 6 Jan 2014
。您是否考虑过更新您的堆栈? devcenter.heroku.com/articles/stack
由于这个问题在过去 2 年没有任何活动并且 OP 已经消失,这可以关闭还是什么?
@AndyMikula 旧版本出现问题,或者可能由较新版本修复,这本身并不是一个有效的关闭原因。如果确实知道解决方案应该更新堆栈,则应该将其添加到问题中作为答案。人们一直在运行旧堆栈,所以这个答案仍然可以帮助某人。 988 次浏览表明该问题确实或确实吸引了人们寻找答案。
【参考方案1】:
这与 2.3 版补丁中修复的 Ruby concurrency issue 有关
您的日志表明您的应用正在运行2.0.0
。将语言版本至少更新到 2.3 的稳定版本可以解决这个问题。这可以通过更改 Gemfile
Ruby 声明轻松完成:
ruby '2.3.8'
【讨论】:
以上是关于异步发送邮件时的“SSL_read:证书已在哈希表中”的主要内容,如果未能解决你的问题,请参考以下文章