Omniauth: ArgumentError: wrong number of arguments (1 for 0) - ruby

I am using Omniauth for login with Facebook but when Callback phase is initiated I get this error:
[2015-01-07T02:26:31.113785 #11509] INFO -- omniauth: (facebook) Request phase initiated.
127.0.0.1 - - [07/Jan/2015:02:26:31 +0100] "GET /auth/facebook HTTP/1.1" 302 239 0.0097
I, [2015-01-07T02:26:31.295848 #11509] INFO -- omniauth: (facebook) Callback phase initiated.
ArgumentError: wrong number of arguments (1 for 0)
/home/ciro/.rvm/gems/ruby-2.1.3/gems/cuba-3.3.0/lib/cuba.rb:317:in `get'
/home/ciro/workspace/iParty/app.rb:25:in `block in <top (required)>'
/home/ciro/.rvm/gems/ruby-2.1.3/gems/cuba-3.3.0/lib/cuba.rb:127:in `instance_eval'
/home/ciro/.rvm/gems/ruby-2.1.3/gems/cuba-3.3.0/lib/cuba.rb:127:in `block in call!'
/home/ciro/.rvm/gems/ruby-2.1.3/gems/cuba-3.3.0/lib/cuba.rb:126:in `catch'
/home/ciro/.rvm/gems/ruby-2.1.3/gems/cuba-3.3.0/lib/cuba.rb:126:in `call!'
/home/ciro/.rvm/gems/ruby-2.1.3/gems/cuba-3.3.0/lib/cuba.rb:111:in `call'
/home/ciro/.rvm/gems/ruby-2.1.3/gems/omniauth-1.2.2/lib/omniauth/strategy.rb:404:in `call_app!'
/home/ciro/.rvm/gems/ruby-2.1.3/gems/omniauth-1.2.2/lib/omniauth/strategy.rb:362:in `callback_phase'
/home/ciro/.rvm/gems/ruby-2.1.3/gems/omniauth-oauth2-1.2.0/lib/omniauth/strategies/oauth2.rb:77:in `callback_phase'
/home/ciro/.rvm/gems/ruby-2.1.3/gems/omniauth-facebook-1.6.0/lib/omniauth/strategies/facebook.rb:71:in `callback_phase'
/home/ciro/.rvm/gems/ruby-2.1.3/gems/omniauth-1.2.2/lib/omniauth/strategy.rb:227:in `callback_call'
I have used Cuba framework (which is very similar to Sinatra). This is my configuration:
app.rb
require "cuba"
require "omniauth-facebook"
Cuba.use Rack::Session::Cookie,
key: ENV['COOKIE_KEY'],
secret: ENV['COOKIE_SECRET']
Cuba.use OmniAuth::Builder do
provider :facebook, ENV['FBK_APP_ID'], ENV['FBK_APP_SECRET']
end
Cuba.define do
on get '/auth/facebook/callback' do
res.write "Autentication with Facebook was successful!"
end
on get '/auth/failure' do
res.write "Something was wrong with Facebook authentication"
end
end
What is missing?

There should be one on-get block defining multiple routes:
Cuba.define do
on get do
on '/auth/facebook/callback' do
res.write "Autentication with Facebook was successful!"
end
on '/auth/failure' do
res.write "Something was wrong with Facebook authentication"
end
end
end

Related

Why is aws-sdk-ruby connecting to '169.254.169.254' on initialization?

I installed the gem webmock, which blocks external connections during the test suite. After I installed it, I got an unexpected result when running the test suite.
I'm somewhat confused why the aws-sdk needs to connect to 169.254.169.254 on initialization?
rspec spec/models/concerns/posconcern_spec.rb
[Coveralls] Set up the SimpleCov formatter.
[Coveralls] Using SimpleCov's 'rails' settings.
An error occurred while loading ./spec/models/concerns/posconcern_spec.rb.
Failure/Error: require File.expand_path('../../config/environment', __FILE__)
WebMock::NetConnectNotAllowedError:
Real HTTP connections are disabled. Unregistered request: GET http://169.254.169.254/latest/meta-data/iam/security-credentials/ with headers {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}
You can stub this request with the following snippet:
stub_request(:get, "http://169.254.169.254/latest/meta-data/iam/security-credentials/").
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
to_return(status: 200, body: "", headers: {})
============================================================
# /home/andey/.rvm/gems/ruby-2.3.4/gems/webmock-3.1.0/lib/webmock/http_lib_adapters/net_http.rb:114:in `request'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/aws-sdk-core/instance_profile_credentials.rb:109:in `http_get'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/aws-sdk-core/instance_profile_credentials.rb:90:in `block (2 levels) in get_credentials'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/aws-sdk-core/instance_profile_credentials.rb:105:in `open_connection'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/aws-sdk-core/instance_profile_credentials.rb:88:in `block in get_credentials'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/aws-sdk-core/instance_profile_credentials.rb:121:in `retry_errors'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/aws-sdk-core/instance_profile_credentials.rb:87:in `get_credentials'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/aws-sdk-core/instance_profile_credentials.rb:73:in `block in refresh'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/aws-sdk-core/instance_profile_credentials.rb:121:in `retry_errors'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/aws-sdk-core/instance_profile_credentials.rb:72:in `refresh'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/aws-sdk-core/refreshing_credentials.rb:20:in `initialize'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/aws-sdk-core/instance_profile_credentials.rb:51:in `initialize'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/aws-sdk-core/credential_provider_chain.rb:90:in `new'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/aws-sdk-core/credential_provider_chain.rb:90:in `instance_profile_credentials'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/aws-sdk-core/credential_provider_chain.rb:12:in `block in resolve'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/aws-sdk-core/credential_provider_chain.rb:11:in `each'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/aws-sdk-core/credential_provider_chain.rb:11:in `resolve'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/aws-sdk-core/plugins/request_signer.rb:37:in `block in <class:RequestSigner>'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/seahorse/client/configuration.rb:70:in `call'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/seahorse/client/configuration.rb:205:in `block in resolve_defaults'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/seahorse/client/configuration.rb:57:in `each'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/seahorse/client/configuration.rb:57:in `each'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/seahorse/client/configuration.rb:204:in `resolve_defaults'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/seahorse/client/configuration.rb:200:in `value_at'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/seahorse/client/configuration.rb:189:in `block in resolve'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/seahorse/client/configuration.rb:189:in `resolve'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/seahorse/client/configuration.rb:177:in `apply_defaults'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/seahorse/client/configuration.rb:150:in `build!'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/seahorse/client/base.rb:68:in `build_config'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/seahorse/client/base.rb:19:in `initialize'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/aws-sdk-core-2.10.52/lib/seahorse/client/base.rb:105:in `new'
# ./config/initializers/aws.rb:1:in `<top (required)>'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:268:in `load'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:268:in `block in load'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:240:in `load_dependency'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:268:in `load'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/railties-4.2.9/lib/rails/engine.rb:652:in `block in load_config_initializer'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/activesupport-4.2.9/lib/active_support/notifications.rb:166:in `instrument'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/railties-4.2.9/lib/rails/engine.rb:651:in `load_config_initializer'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/railties-4.2.9/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/railties-4.2.9/lib/rails/engine.rb:615:in `each'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/railties-4.2.9/lib/rails/engine.rb:615:in `block in <class:Engine>'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/railties-4.2.9/lib/rails/initializable.rb:30:in `instance_exec'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/railties-4.2.9/lib/rails/initializable.rb:30:in `run'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/railties-4.2.9/lib/rails/initializable.rb:55:in `block in run_initializers'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/railties-4.2.9/lib/rails/initializable.rb:44:in `each'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/railties-4.2.9/lib/rails/initializable.rb:44:in `tsort_each_child'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/railties-4.2.9/lib/rails/initializable.rb:54:in `run_initializers'
# /home/andey/.rvm/gems/ruby-2.3.4/gems/railties-4.2.9/lib/rails/application.rb:352:in `initialize!'
# ./config/environment.rb:5:in `<top (required)>'
# ./spec/rails_helper.rb:3:in `require'
# ./spec/rails_helper.rb:3:in `<top (required)>'
# ./spec/models/concerns/posconcern_spec.rb:1:in `require'
# ./spec/models/concerns/posconcern_spec.rb:1:in `<top (required)>'
Relevant link to repo:
https://github.com/aws/aws-sdk-ruby/blob/master/gems/aws-sdk-core/lib/aws-sdk-core/instance_profile_credentials.rb#L45
It is trying to connect to the AWS metadata server to get the AWS credentials. All AWS servers should be able to connect to the internal metadata server.
I installed the gem webmock, which blocks external connections during
the test suite
How are you blocking it? Firewall? Add a rule to allow traffic to 169.254.169.254 or stub it.
The script is trying to connect to AWS services. For that it needs credentials which can be provided in many ways. One way is to use AWS IAM role and fetch the credentials dynamically from the metadata server (169.254.169.254). Your script is connecting to 169.254.169.254 to fetch the credentials. It can be used to connect to AWS services later.
This is a follow up to #helloV 's answer.
Full documentation on
http://169.254.169.254/latest/meta-data/iam/security-credentials/
An application on the instance retrieves the security credentials
provided by the role from the instance metadata item
iam/security-credentials/role-name. The application is granted the
permissions for the actions and resources that you've defined for the
role through the security credentials associated with the role. These
security credentials are temporary and we rotate them automatically.
We make new credentials available at least five minutes prior to the
expiration of the old credentials.
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#instance-metadata-security-credentials
Had a tough time researching on how to stub it. Will share my findings here hope it'll help other people.
Since AWS uses service name to fetch credentials for multiple services such as S3, any IAM Role, SQS etc.
But when dealing with IAM roles AWS hits http://169.254.169.254/latest/meta-data/iam/security-credentials/ which return the role name attached onto the machine and using the response of the same it hits the curl http://169.254.169.254/latest/meta-data/iam/security-credentials/#{role}.
So we need to stub both of the curls in order to successfully mock the IAM role. Below is the code for the same.
def self.auth(params = {})
status = params[:status].presence || 200
url = 'http://169.254.169.254/latest/meta-data/iam/security-credentials/'
WebMock.stub_request(:get, url)
.with({headers: request_headers}.compact)
.to_return(status: status, body: 'SampleRole', headers: {})
end
def self.role_auth(role = 'SampleRole')
url = "http://169.254.169.254/latest/meta-data/iam/security-credentials/#{role}"
WebMock.stub_request(:get, url)
.with({headers: request_headers}.compact)
.to_return(status: 200, body: sample_response, headers: {})
end
private
def self.request_headers
{
'Accept': '*/*',
'Accept-Encoding': 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'User-Agent': 'aws-sdk-ruby3/3.21.2'
}.with_indifferent_access
end
def self.sample_response
{
Code: 'Success',
LastUpdated: '2020-05-08T05:55:23Z',
Type: 'AWS-HMAC',
AccessKeyId: Faker::Lorem.characters(10),
SecretAccessKey: Faker::Lorem.characters(20),
Token: Faker::Lorem.characters(60),
Expiration: '2020-05-08T12:00:45Z'
}.to_json
end
So whenver any rspec uses InstanceCredentials provider you need to stub both of the above defined requests in before block of each of the rspec.
Example:
before do
ApiStub::IamCred.auth
ApiStub::IamCred.role_auth
end
Hope it helps.
Happy Coding
There are some good answers in this thread on how to stub this. Another alternative (a better one?) is to eliminate the need for thE SDK to check for credentials from the instance meta data service. You can do this by providing credentials. These can be fake. A simple way to do this would be to provide credential via the ENV (e.g. ENV['AWS_ACCESS_TOKEN'] and ENV['SECRET_ACCESS_TOKEN']).

How to fix a deadlock caused by open

I have is a deadlock, but I am not using any threads in my program. Plus, the error only happens about once every 1000 to 1500 function calls, making it very difficult to pinpoint and correct.
Here is the complete error message when the issue occurs:
/usr/lib/ruby/2.3.0/timeout.rb:95:in `join': No live threads left. Deadlock? (fatal)
from /usr/lib/ruby/2.3.0/timeout.rb:95:in `ensure in block in timeout'
from /usr/lib/ruby/2.3.0/timeout.rb:95:in `block in timeout'
from /usr/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
from /usr/lib/ruby/2.3.0/net/http.rb:878:in `connect'
from /usr/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
from /usr/lib/ruby/2.3.0/net/http.rb:852:in `start'
from /usr/lib/ruby/2.3.0/open-uri.rb:319:in `open_http'
from /usr/lib/ruby/2.3.0/open-uri.rb:737:in `buffer_open'
from /usr/lib/ruby/2.3.0/open-uri.rb:212:in `block in open_loop'
from /usr/lib/ruby/2.3.0/open-uri.rb:210:in `catch'
from /usr/lib/ruby/2.3.0/open-uri.rb:210:in `open_loop'
from /usr/lib/ruby/2.3.0/open-uri.rb:151:in `open_uri'
from /usr/lib/ruby/2.3.0/open-uri.rb:717:in `open'
from /usr/lib/ruby/2.3.0/open-uri.rb:35:in `open'
from /home/mat/travail_perso/RUBY/MangaScrapp_github/sources/utils.rb:85:in `get_pic'
from /home/mat/travail_perso/RUBY/MangaScrapp_github/mangafox/MF_download.rb:87:in `page_link'
from /home/mat/travail_perso/RUBY/MangaScrapp_github/mangafox/MF_download.rb:116:in `chapter_link'
from /home/mat/travail_perso/RUBY/MangaScrapp_github/mangafox/MF_download.rb:142:in `chapter'
from /home/mat/travail_perso/RUBY/MangaScrapp_github/mangafox/MF_update.rb:57:in `block in MF_manga_missing_chapters'
from /home/mat/travail_perso/RUBY/MangaScrapp_github/mangafox/MF_update.rb:45:in `reverse_each'
from /home/mat/travail_perso/RUBY/MangaScrapp_github/mangafox/MF_update.rb:45:in `MF_manga_missing_chapters'
from /home/mat/travail_perso/RUBY/MangaScrapp_github/mangafox/MF_update.rb:80:in `MF_update'
from /home/mat/travail_perso/RUBY/MangaScrapp_github/sources/update.rb:5:in `update_manga'
from /home/mat/travail_perso/RUBY/MangaScrapp_github/sources/update.rb:15:in `block in update_all'
from /home/mat/travail_perso/RUBY/MangaScrapp_github/sources/update.rb:14:in `each'
from /home/mat/travail_perso/RUBY/MangaScrapp_github/sources/update.rb:14:in `update_all'
from /home/mat/travail_perso/RUBY/MangaScrapp_github/sources/update.rb:22:in `update'
from ./MangaScrap.rb:28:in `<main>'
The link to the complete program is https://github.com/Hellfire01/MangaScrap
The issue happens to the three different methods that use open. Here is the one that crashed this time:
# conect to link and download picture
def get_pic(link)
safe_link = link.gsub(/[\[\]]/) { '%%%s' % $&.ord.to_s(16) }
tries ||= 20
begin
page = open(safe_link, "User-Agent" => "Ruby/#{RUBY_VERSION}")
rescue URI::InvalidURIError => error
puts "Warning : bad url"
puts link
puts "message is : " + error.message
return nil
rescue => error
if tries > 0
tries -= 1
sleep(0.2)
retry
else
puts 'could not get picture ' + safe_link + ' after ' + $nb_tries.to_s + ' tries'
puts "message is : " + error.message
return nil
end
end
sleep(0.2)
return page
end
Here is the link to the file: https://github.com/Hellfire01/MangaScrap/blob/master/sources/utils.rb
I would like to know:
How can I fix this error?
If I can not fix this error, are there alternatives to OpenUri that I can use?
You're not catching all exceptions here. When nothing is specified after rescue, it means that you're catching StandardError which is not at the root of Exceptions' hierarchy.
If you want to make sure you're catching all exceptions and retry opening a URL (or whatever behavior you'd like), what you want to do is:
rescue Exception => error

undefined method `query_options' for nil:NilClass, resque, unicorn, Rails 4, mysql

I get this error when i try to send an update mail.
undefined method `query_options' for nil:NilClass
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:218:in `execute'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:300:in `execute_and_free'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:461:in `columns'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:114:in `block in prepare_default_proc'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:56:in `yield'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:56:in `default'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:56:in `columns'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/model_schema.rb:208:in `columns'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/model_schema.rb:217:in `columns_hash'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:60:in `block in valid?'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:60:in `each'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:60:in `all?'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:60:in `valid?'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:18:in `method_missing'
/home/user_name/work/app_name/app/mailers/user_mailer.rb:12:in `update_message'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/actionpack-4.0.0/lib/abstract_controller/base.rb:189:in `process_action'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/actionpack-4.0.0/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:373:in `_run__1485230712795781007__process_action__callbacks'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:80:in `run_callbacks'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/actionpack-4.0.0/lib/abstract_controller/callbacks.rb:17:in `process_action'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/actionpack-4.0.0/lib/abstract_controller/base.rb:136:in `process'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/actionpack-4.0.0/lib/abstract_controller/rendering.rb:44:in `process'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/actionmailer-4.0.0/lib/action_mailer/base.rb:503:in `process'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/actionmailer-4.0.0/lib/action_mailer/base.rb:497:in `initialize'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/resque_mailer-2.2.6/lib/resque_mailer.rb:48:in `new'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/resque_mailer-2.2.6/lib/resque_mailer.rb:48:in `perform'
We are using Rails 4, unicorn 4.7 and resque 1.25.
For sending emails on the application we use different mailer.
The recovery email that uses the object to send the emails, works fine, but the email that sends the profile update, which queries the user by id, does not work and throws the above error.
This is the unicorn config:
worker_processes 1
working_directory "correct/path" # available in 0.94.0+
listen "correct/path", :backlog => 64
timeout 30
pid "correct/path"
stderr_path "correct/path"
stdout_path "correct/path"
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
before_fork do |server, worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
old_pid = "#{server.config[:pid]}.oldbin"
if old_pid != server.pid
begin
sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
Process.kill(sig, File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
end
end
end
after_fork do |server, worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
I have tried various answer from stack overflow, or Github issues with no result.
I finally fixed the problem, I had to restart the worker(s) after removing the octopus gem.
That error message is because octopus does not work very well out of the box with unicorn so I did configured it, but I forgot to close the worker, and it kept the octopus setting thus throwing this error.
Unfortunately I could not find a good way to use octopus with our applications because we got this error, that as far as I could see is related to Resque, more precisely when any of the workers forks a process, it fails to connect to an outside database, ex: x model connecting to y database., which works well for the application using octopus_connect, but not for the workers.
Our solution was to use instead taskrabbit/makara as the connection proxy.

Ruby on Windows send email using SMTP library

I have the following code that works perfectly on a Mac but fails on windows.
require 'net/smtp'
opts = {}
opts[:server] ||= 'mycompany.com'
opts[:from] ||= 'user0#mycompany.com'
opts[:from_alias] ||= 'Example'
opts[:subject] ||= "You need to see this"
opts[:body] ||= "Important stuff!"
msg = <<END_OF_MESSAGE
From: #{opts[:from_alias]} <#{opts[:from]}>
To: <user0#mycompany.com>
Subject: #{opts[:subject]}
#{opts[:body]}
END_OF_MESSAGE
Net::SMTP.start(opts[:server]) do |smtp|
smtp.send_message msg, opts[:from], "user0#mycompany.com"
end
With the following error message...
Z:\util>ruby test.rb
C:/Ruby200/lib/ruby/2.0.0/net/smtp.rb:540:in `initialize': Permission denied - c
onnect(2) (Errno::EACCES)
from C:/Ruby200/lib/ruby/2.0.0/net/smtp.rb:540:in `open'
from C:/Ruby200/lib/ruby/2.0.0/net/smtp.rb:540:in `tcp_socket'
from C:/Ruby200/lib/ruby/2.0.0/net/smtp.rb:550:in `block in do_start'
from C:/Ruby200/lib/ruby/2.0.0/timeout.rb:66:in `timeout'
from C:/Ruby200/lib/ruby/2.0.0/net/smtp.rb:549:in `do_start'
from C:/Ruby200/lib/ruby/2.0.0/net/smtp.rb:519:in `start'
from C:/Ruby200/lib/ruby/2.0.0/net/smtp.rb:456:in `start'
from test.rb:19:in `<main>'
Is there something missing that i need on the windows environment to send the email?
Thanks

Debugging mail delivery in IronWorker

I'm trying to use the mail gem to send an email from an IronWorker task. Running the script works on my local system (OS X), but fails when run on IronWorker with the same parameters. I'm new to IronWorker and the mail gem, so I'm at a loss of where to start debugging. Here's the text of the error message.
/task/email.rb:5:in `block in <top (required)>': undefined method `[]' for nil:NilClass (NoMethodError)
from /task/__gems__/gems/mail-2.4.4/lib/mail/mail.rb:106:in `instance_eval'
from /task/__gems__/gems/mail-2.4.4/lib/mail/mail.rb:106:in `defaults'
from /task/email.rb:3:in `<top (required)>'
from /usr/local/lib/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/lib/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from __runner__.rb:213:in `<main>'
And here's my code:
require 'mail'
Mail.defaults do
delivery_method :smtp, {
address: params['address'],
port: 587,
domain: params['domain'],
user_name: params['username'],
password: params['password'],
authentication: 'plain',
enable_starttls_auto: true
}
end
Mail.deliver do
to "#{params['to_name']} <#{params['to_address']}>"
from "#{params['from_name']} <#{params['from_address']}>"
subject "Mail test"
text_part do
body params['text']
end
html_part do
content_type 'text/html; charset=UTF-8'
body params['html']
end
end
Note that I was getting this error before locally, but it was caused by using username in the defaults instead of user_name. Any ideas?
I'm not sure but looks like 'params' is nil, could you try to inspect it before using in. It could happened if you're using in your worker separate namespaces (like worker body inside class)

Resources