Rails 3 - 设计/ActionMailer/RUBY-SMTP 导致分段错误 [英] Rails 3 - Devise/ActionMailer/RUBY-SMTP causing a segmentation fault
问题描述
好的 - 我在这里有点过头了.我正在使用:
OK - I'm in way over my head here. I'm using:
- ruby-1.9.3-p0
- rails-3.1.3
- mail-2.3.0
- devise-1.5.3
尝试打开 Devise 的 :confirmable
选项并在我的应用程序中启动 smtp 服务.添加 /config/initializers/setup_mail.rb
后,在我的数据库中添加 Devise 的必要列,并将 :confirmable
属性添加到我的 User
模型,我得到一个分段错误.它在用户注册后立即发生.Devise
正在尝试发送确认电子邮件,导致 ruby smtp 库崩溃并显示以下内容:
Trying to turn on Devise's :confirmable
option and start up smtp services in my app. As soon as I add /config/initializers/setup_mail.rb
, add Devise's necessary columns in my DB, and the :confirmable
attribute to my User
model, I get a segmentation fault. It occurs right after a user signs up. Devise
is trying to send out the confirmation email, causing the ruby smtp library to crash with the following:
... lib/ruby/1.9.1/net/smtp.rb:583: [BUG] Segmentation fault
log/development.log
中的最后一项:
Rendered devise/mailer/confirmation_instructions.html.erb (1.2ms)
我的 /config/initializers/setup_mail.rb
文件:
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "mydomain.com",
:user_name => "support@mydomain.com",
:password => "???????",
:authentication => "plain",
:enable_starttls_auto => true
}
ActionMailer::Base.default_url_options[:host] = "localhost:3000"
我的 config/environments/development.rb
文件有以下内容:
My config/environments/development.rb
file has the following:
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
这是来自 ruby/1.9.1/net/smtp.rb 的相关代码(第 583 行靠近中间):
Here is the germane code from ruby/1.9.1/net/smtp.rb (line 583 is near the middle):
def ssl_socket(socket, context)
OpenSSL::SSL::SSLSocket.new socket, context
end
def tlsconnect(s)
verified = false
s = ssl_socket(s, @ssl_context)
logging "TLS connection started"
s.sync_close = true
s.connect # THIS IS LINE 583
if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
s.post_connection_check(@address)
end
verified = true
s
ensure
s.close unless verified
end
当 smtp 尝试通过 SSL 套接字连接 ( s.connect
) 进行连接时,似乎发生了分段错误.在 setup_mail.rb
中,我尝试将 :enable_starttls_auto
设置为 true
和 false
.当它设置为 false
但没有电子邮件发出时,我没有收到分段错误,所以这是没用的.
It looks like the segmentation fault occurs when smtp is trying to connect via a SSL socket connection ( s.connect
). In setup_mail.rb
I've tried setting :enable_starttls_auto
to both true
and false
. I don't get the segmentation fault when it is set to false
but no email goes out, so that is useless.
通过在我的 Mac 上运行以下命令,我可以轻松连接到 gmail 的 smtp 服务:
I'm easily able to connect to gmail's smtp service by running this command from my Mac:
$ telnet smtp.gmail.com 587
不确定从这里去哪里 - 有什么建议吗?
Not sure where to go from here - any suggestions?
推荐答案
问题在于 Rails 与 OpenSSL 交互的方式.这个帖子总结的很好.http://www.22ideastreet.com/debug/smtp-rb14-错误分段错误/
The issue is with the way Rails interacts with OpenSSL. This post sums it up very well. http://www.22ideastreet.com/debug/smtp-rb14-bug-segmentation-fault/
解决方法是将其添加到您的 .bashrc/.zshrc/.bash_profile
The fix is to add this to your .bashrc/.zshrc/.bash_profile
export RUBYOPT="-ropenssl"
这篇关于Rails 3 - 设计/ActionMailer/RUBY-SMTP 导致分段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!