Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

errors thrown when sending emails within multiple threads #90

Closed
desheikh opened this issue Dec 3, 2012 · 7 comments
Closed

errors thrown when sending emails within multiple threads #90

desheikh opened this issue Dec 3, 2012 · 7 comments

Comments

@desheikh
Copy link

desheikh commented Dec 3, 2012

tested using ruby 1.9.3-p327

require 'aws-sdk'
pool = Array.new(10) do |i|
  Thread.new do
    AWS::SimpleEmailService.new(:access_key_id => '1234567890', :secret_access_key => '1234567890').send_email(
      :subject => 'subject',
      :body_html => 'body_html',
      :body_text => 'body_text',
      :to => 'success@simulator.amazonses.com',
      :from => 'some@email.com',
    )
  end
end

pool.each(&:join)

~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/aws-sdk-1.7.1/lib/aws/core/client.rb:499:in build_request': undefined methodadd_authorization!' for #AWS::SimpleEmailService::Request:0x007feac892bd90 (NoMethodError)

~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/aws-sdk-1.7.1/lib/aws/simple_email_service.rb:281:in send_email': undefined methodsend_email' for #AWS::SimpleEmailService::Client:0x007fdf7c1465c8 (NoMethodError)

@trevorrowe
Copy link
Member

Thank you for reporting this issue. There appears to be a thread-safety issue with how the service interfaces (e.g. AWS::SimpleEmailService) construct their client. I will try to resolve this issue soon, but you should be able to work around this by constructing the ses interface outside the loop:

require 'aws-sdk'
ses = AWS::SimpleEmailService.new(...)
pool = Array.new(10) do |i|
Thread.new do
  ses.send_email(
    :subject => 'subject',
    :body_html => 'body_html',
    :body_text => 'body_text',
    :to => 'success@simulator.amazonses.com',
    :from => 'some@email.com',
  )
  end
end

pool.each(&:join)

Please watch this issue for updates.

@desheikh
Copy link
Author

@trevorrowe, thanks for the response, but please note that keeping the initialization out of the loop will still have the same issue.

~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/aws-sdk-1.7.1/lib/aws/core/signature/version_4.rb:87:in `service': NotImplementedError (NotImplementedError)

~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/aws-sdk-1.7.1/lib/aws/core/client.rb:499:in build_request': undefined methodadd_authorization!' for #AWS::SimpleEmailService::Request:0x007fdff13558d0 (NoMethodError)

@trevorrowe
Copy link
Member

Given the following example

require 'aws-sdk'
ses = AWS::SimpleEmailService.new # loading credentials from environment
pool = Array.new(10) do |i|
Thread.new do
  ses.send_email(
    :subject => 'subject',
    :body_html => 'body_html',
    :body_text => 'body_text',
    :to => 'success@simulator.amazonses.com',
    :from => 'some@email.com', # replace this with a verified email address
  )
  end
end

pool.each(&:join)

I was able to execute this many times without issue. If I moved the ses assignment inside the Thread.new block, then it would fail every time due to thread safety issues. Is this what your test example looks like?

@desheikh
Copy link
Author

@trevorrowe, I've been able to execute it multiple times without issue as well, but If I keep at it I do get the occasional add_authorization error. Havn't been able to reproduce the error at "version_4.rb:87" again though.

My test file is exactly the same except for the array size which I've set to 90 and of course the from email.

@trevorrowe
Copy link
Member

@desheikh I just pushed a commit that resolves an issue with AWS::Core::Configuration. I then took your original example and added one line. Between the two, this resolved the issue for me.

AWS.eager_autoload!

I realize this is not an ideal fix. It forcibly loads all AWS classes up-front, which can be slow, but it is a one-time cost. That said, this is not an issue in Ruby 2.0 and you can drop the call to eager_autoload! if you are able to upgrade.

@trevorrowe
Copy link
Member

Closing this issue as it should work properly if all classes have been eagerly auto-loaded. Please re-open if you still run into issues.

@desheikh
Copy link
Author

Hi,
Thanks, I just tested out sending mails out with the latest version of the sdk and so far have not experienced any issues yet even without the eager_autoload.
AWS.eager_autoload! raises an exception though, created a separate issue for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants