Email failing with network timeout

AI-generated summary

The user nrbrt reports that outgoing email stopped working after updating from v2.2.0.beta5 to v2.2.0.beta6, with a network timeout error in the logs. The error indicates a failure during SMTP connection setup, resulting in a 422 Unprocessable Entity response. codinghorror identifies this as a networking issue, not a code problem, due to the long timeout. nrbrt confirms this by testing connectivity to the mail server, finding it unreachable from the hosted Discourse server but reachable from their home machine, indicating a network configuration problem.

After I updated from v2.2.0.beta5 version ed546a0 to v2.2.0.beta6 version 6213e02, our outgoing mail stopped working. When I try to send a test mail, it tells me to check my app.yml, but that has not changed since early november this year but I tested the settings mentioned in the yaml file anyway and it checked out ok.
After sending a test mail, my production.log shows this:

Started POST "/admin/email/test" for 111.111.111.111 at 2018-12-29 07:40:29 +0000
Processing by Admin::EmailController#test as */*
Parameters: {"email_address"=>"xyz@gmail.com"}
Sent mail to xyz@gmail.com (30004.6ms)
Completed 422 Unprocessable Entity in 30062ms (Views: 0.5ms | ActiveRecord: 4.2ms)

error logs show this:

Job exception: execution expired

/usr/local/lib/ruby/2.5.0/net/smtp.rb:539:in `initialize' /usr/local/lib/ruby/2.5.0/net/smtp.rb:539:in `open' /usr/local/lib/ruby/2.5.0/net/smtp.rb:539:in `tcp_socket' /usr/local/lib/ruby/2.5.0/net/smtp.rb:549:in `block in do_start' /usr/local/lib/ruby/2.5.0/timeout.rb:103:in `timeout' /usr/local/lib/ruby/2.5.0/net/smtp.rb:548:in `do_start' /usr/local/lib/ruby/2.5.0/net/smtp.rb:518:in `start' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/mail-2.7.1.rc1/lib/mail/network/delivery_methods/smtp.rb:109:in `start_smtp_session' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/mail-2.7.1.rc1/lib/mail/network/delivery_methods/smtp.rb:100:in `deliver!' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/mail-2.7.1.rc1/lib/mail/message.rb:2159:in `do_delivery' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/mail-2.7.1.rc1/lib/mail/message.rb:260:in `block in deliver' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/actionmailer-5.2.2/lib/action_mailer/base.rb:560:in `block in deliver_mail' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/notifications.rb:168:in `block in instrument' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/notifications/instrumenter.rb:23:in `instrument' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/notifications.rb:168:in `instrument' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/actionmailer-5.2.2/lib/action_mailer/base.rb:558:in `deliver_mail' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/mail-2.7.1.rc1/lib/mail/message.rb:260:in `deliver' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/actionmailer-5.2.2/lib/action_mailer/message_delivery.rb:114:in `block in deliver_now' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/actionmailer-5.2.2/lib/action_mailer/rescuable.rb:17:in `handle_exceptions' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/actionmailer-5.2.2/lib/action_mailer/message_delivery.rb:113:in `deliver_now' /var/www/discourse/lib/email/sender.rb:197:in `send' /var/www/discourse/app/jobs/regular/user_email.rb:57:in `execute' /var/www/discourse/app/jobs/regular/critical_user_email.rb:14:in `execute' /var/www/discourse/app/jobs/base.rb:137:in `block (2 levels) in perform' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/rails_multisite-2.0.4/lib/rails_multisite/connection_management.rb:63:in `with_connection' /var/www/discourse/app/jobs/base.rb:127:in `block in perform' /var/www/discourse/app/jobs/base.rb:123:in `each' /var/www/discourse/app/jobs/base.rb:123:in `perform' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:187:in `execute_job' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:169:in `block (2 levels) in process' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/middleware/chain.rb:128:in `block in invoke' /var/www/discourse/lib/sidekiq/pausable.rb:81:in `call' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/middleware/chain.rb:130:in `block in invoke' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/middleware/chain.rb:133:in `invoke' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:168:in `block in process' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:139:in `block (6 levels) in dispatch' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/job_retry.rb:98:in `local' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:138:in `block (5 levels) in dispatch' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq.rb:36:in `block in <module:Sidekiq>' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:134:in `block (4 levels) in dispatch' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:199:in `stats' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:129:in `block (3 levels) in dispatch' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/job_logger.rb:8:in `call' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:128:in `block (2 levels) in dispatch' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/job_retry.rb:73:in `global' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:127:in `block in dispatch' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/logging.rb:48:in `with_context' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/logging.rb:42:in `with_job_hash_context' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:126:in `dispatch' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:167:in `process' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:85:in `process_one' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:73:in `run' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/util.rb:16:in `watchdog' /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/util.rb:25:in `block in safe_thread'

In Sidekik I see email jobs being retried and never succeed. For instance:

Job: Jobs::CriticalUserEmail
Error: Jobs::HandledExceptionWrapper::WrappedNet::OpenTimeout: execution expired

I tried restarting discourse and even the entire machine, but no dice. Can anyone help me please? I am at a loss. I promise to migrate to the stable releases after this!

This is a networking problem, not a code problem.

A networking problem? how so? it worked fine until I updated.

Network timeouts, 30+ seconds.

Wow…I just tried to ping the mailserver and it does not reply from our hosted discourse server, but does reply from my home machine! I have been barking up the wrong tree, sorry for that but thanks so much for your help!