【Ruby On Rails 】 EOFError (end of file reached):エラー


ActiveMailerでメール送信しようとすると以下のようなエラーが・・。
開発環境では問題なく動作するけど、本番環境に移した時にたまにこのエラーがでる。
毎回忘れて調べてたので自分用メモ。

エラー内容

Railsログ↓

EOFError (end of file reached):
/usr/local/lib/ruby/1.8/net/protocol.rb:135:in `sysread’
/usr/local/lib/ruby/1.8/net/protocol.rb:135:in `rbuf_fill’
/usr/local/lib/ruby/1.8/timeout.rb:62:in `timeout’
/usr/local/lib/ruby/1.8/timeout.rb:93:in `timeout’
/usr/local/lib/ruby/1.8/net/protocol.rb:134:in `rbuf_fill’
/usr/local/lib/ruby/1.8/net/protocol.rb:116:in `readuntil’
/usr/local/lib/ruby/1.8/net/protocol.rb:126:in `readline’
/usr/local/lib/ruby/1.8/net/smtp.rb:911:in `recv_response’
/usr/local/lib/ruby/1.8/net/smtp.rb:554:in `do_start’
/usr/local/lib/ruby/1.8/net/smtp.rb:921:in `critical’
/usr/local/lib/ruby/1.8/net/smtp.rb:554:in `do_start’
/usr/local/lib/ruby/1.8/net/smtp.rb:525:in `start’
app/controllers/contact_controller.rb:39:in `create’
passenger (2.2.11) lib/phusion_passenger/rack/request_handler.rb:92:in `process_request’
passenger (2.2.11) lib/phusion_passenger/abstract_request_handler.rb:207:in `main_loop’
passenger (2.2.11) lib/phusion_passenger/railz/application_spawner.rb:418:in `start_request_handler’
passenger (2.2.11) lib/phusion_passenger/railz/application_spawner.rb:358:in `handle_spawn_application’
passenger (2.2.11) lib/phusion_passenger/utils.rb:184:in `safe_fork’
passenger (2.2.11) lib/phusion_passenger/railz/application_spawner.rb:354:in `handle_spawn_application’
passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:352:in `__send__’
passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:352:in `main_loop’
passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously’
passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:163:in `start’
passenger (2.2.11) lib/phusion_passenger/railz/application_spawner.rb:213:in `start’
passenger (2.2.11) lib/phusion_passenger/spawn_manager.rb:262:in `spawn_rails_application’
passenger (2.2.11) lib/phusion_passenger/abstract_server_collection.rb:126:in `lookup_or_add’
passenger (2.2.11) lib/phusion_passenger/spawn_manager.rb:256:in `spawn_rails_application’
passenger (2.2.11) lib/phusion_passenger/abstract_server_collection.rb:80:in `synchronize’
passenger (2.2.11) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize’
passenger (2.2.11) lib/phusion_passenger/spawn_manager.rb:255:in `spawn_rails_application’
passenger (2.2.11) lib/phusion_passenger/spawn_manager.rb:154:in `spawn_application’
passenger (2.2.11) lib/phusion_passenger/spawn_manager.rb:287:in `handle_spawn_application’
passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:352:in `__send__’
passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:352:in `main_loop’
passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously’

メールログ↓ (/var/log/maillog)

May 18 09:06:44 sample postfix/smtpd[5962]: connect from test.jp[127.0.0.1]
May 18 09:06:44 sample postfix/smtpd[5962]: warning: SASL: Connect to private/auth failed: Connection refused
May 18 09:06:44 sample postfix/smtpd[5962]: fatal: no SASL authentication mechanisms
May 18 09:06:45 sample postfix/master[15951]: warning: process /usr/libexec/postfix/smtpd pid 5962 exit status 1
May 18 09:06:45 sample postfix/master[15951]: warning: /usr/libexec/postfix/smtpd: bad command startup — throttling

解決方法

postfixの設定ファイルmain.cfを以下のように修正すると治った。
使用していたサーバー環境がデフォルトで「private/auth」設定になっていたのが問題でした。

[変更前]

smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth

[変更後]

yum install cyrus-sasl-plain
yum install cyrus-sasl-md5

以下のパッケージをインストールする。

smtpd_sasl_type = cyrus
smtpd_sasl_path = smtpd

これでpostfixを再起動すると無事動きました。

参考サイト

△Postfix の SMTP-AUTH 設定でハマる
http://holy.enyou.org/2009/07/02/postfix-smtp-auth-config-bothered-m/
△2008-03-29 Postfixの設定メモ
http://d.hatena.ne.jp/yas65/20080329