无法通过AWS-SES和Sidekiq发送电子邮件

时间:2018-07-09 08:10:41

标签: ruby ruby-on-rails-4 aws-sdk sidekiq amazon-ses

我们正在从DelayedJob迁移到Sidekiq。看起来一切正常,除了我们使用亚马逊的SES发送电子邮件。我认为该问题是线程安全问题之一。

每当我们排队超过1封电子邮件时,我们都会收到大量此类错误

WARN EmailJob::perform IOError closed stream #<SendMailQueueItemWorker:0x00007f7fb00b7ae8 @jid="242cafc31a55b6121959103f"> /usr/local/rubies/2.3.7/lib/ruby/2.3.0/net/protocol.rb:176:in `wait_readable'
/usr/local/rubies/2.3.7/lib/ruby/2.3.0/net/protocol.rb:176:in `rbuf_fill'
/usr/local/rubies/2.3.7/lib/ruby/2.3.0/net/protocol.rb:124:in `read'
/usr/local/rubies/2.3.7/lib/ruby/2.3.0/net/http/response.rb:291:in `block in read_body_0'
/usr/local/rubies/2.3.7/lib/ruby/2.3.0/net/http/response.rb:276:in `inflater'
/usr/local/rubies/2.3.7/lib/ruby/2.3.0/net/http/response.rb:281:in `read_body_0'
/usr/local/rubies/2.3.7/lib/ruby/2.3.0/net/http/response.rb:202:in `read_body'
/usr/local/rubies/2.3.7/lib/ruby/2.3.0/net/http.rb:1408:in `block in send_entity'
/mnt/xxx-production/shared/bundle/ruby/2.3.0/gems/aws-sdk-core-3.22.1/lib/seahorse/client/net_http/patches.rb:40:in `block in new_transport_request'

EmailJob::perform OpenSSL::SSL::SSLError SSL_connect returned=1 errno=0 state=unknown state: unexpected record #<SendMailQueueItemWorker:0x000055c08033f748 @jid="47a8cdc65878dcaa9e6ad817"> /usr/local/rubies/2.3.7/lib/ruby/2.3.0/net/protocol.rb:44:in `connect_nonblock'
/usr/local/rubies/2.3.7/lib/ruby/2.3.0/net/protocol.rb:44:in `ssl_socket_connect'
/usr/local/rubies/2.3.7/lib/ruby/2.3.0/net/http.rb:928:in `connect'
/usr/local/rubies/2.3.7/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
/usr/local/rubies/2.3.7/lib/ruby/2.3.0/net/http.rb:852:in `start'
/usr/local/rubies/2.3.7/lib/ruby/2.3.0/net/http.rb:1384:in `request'
/usr/local/rubies/2.3.7/lib/ruby/2.3.0/net/http.rb:1407:in `send_entity'
/usr/local/rubies/2.3.7/lib/ruby/2.3.0/net/http.rb:1195:in `post'
/mnt/xxx-production/shared/bundle/ruby/2.3.0/bundler/gems/aws-ses-feac6b6b069d/lib/aws/ses/base.rb:165:in `request'
/mnt/xxx-production/shared/bundle/ruby/2.3.0/bundler/gems/aws-ses-feac6b6b069d/lib/aws/ses/send_email.rb:103:in `send_raw_email'

多年来,该代码与从DelayedJob内部调用的代码完全相同,而没有任何问题。

在这里我们能做些什么吗?还是回到DJ进行与亚马逊相关的电话?我们对不同的Amazon服务打了很多电话。

1 个答案:

答案 0 :(得分:1)

听起来像您正在尝试在多个线程中使用一个全局AWS连接。这是Sidekiq和DJ之间的最大区别:您的代码必须是线程安全的。切换到连接池。

https://github.com/mperham/sidekiq/wiki/Advanced-Options#connection-pooling