Rails Mailer “Net::OpenTimeout: execution expired” Exception on production server only

前端 未结 8 1288
南方客
南方客 2020-12-05 04:19

I am using Ruby MRI 2.0.0 and Rails 3.2.12 on a Ubuntu 12.04 TLS VPS and attempting to setup email notifications in my app. It was working fine a few days ago, but n

相关标签:
8条回答
  • 2020-12-05 04:41

    I probably had the same issue, my production application didn't send mails although everything in development was working fine. I also got the "Net::OpenTimeout" error.

    My problem was that i was using a Google server in production, and it blocks ports 25, 465 and 587 on outbound connections.

    Since I was using Mandrill for sending mails, I was able to switch the connecting port from 587 to 2525 and everything is okay now.

    0 讨论(0)
  • 2020-12-05 04:44

    The issue was due to an IPv6 misconfiguration on the production server and has now been fixed.

    0 讨论(0)
  • 2020-12-05 04:44

    I added these to /etc/gai.conf in CentOS7 and it worked.

    label       ::1/128        0
    label       ::/0           1
    label       2002::/16      2
    label       ::/96          3
    label       ::ffff:0:0/96  4
    precedence  ::1/128        50
    precedence  ::/0           40
    precedence  2002::/16      30
    precedence  ::/96          20
    precedence  ::ffff:0:0/96  100
    

    http://blog.asiantuntijakaveri.fi/2014/12/prefer-ipv4-over-ipv6-on-centos-6.html:title

    0 讨论(0)
  • 2020-12-05 04:46

    Try this, if all above fails

    I got it solved by adding this in application.rb under config

     require 'net/http'
    
     require 'openssl'
    
     require 'resolv-replace'
    
    0 讨论(0)
  • 2020-12-05 04:50

    Here is also a temporary fix that may come in handy while waiting for your hosting provider to fix the issue:

    Add the following lines to /etc/sysctl.conf:

    #disable ipv6
    net.ipv6.conf.all.disable_ipv6 = 1
    net.ipv6.conf.default.disable_ipv6 = 1
    net.ipv6.conf.lo.disable_ipv6 = 1
    

    Now reload the sysctl service using the following command:

    sudo sysctl -p
    

    Now the apps are able to send emails again.

    You can always know if IPv6 is enabled calling

    cat /proc/sys/net/ipv6/conf/all/disable_ipv6
    

    from terminal. Two possible answers: 0 => IPv6 is enabled; 1 => IPv6 disabled.

    From: https://serverfault.com/questions/512744/timeout-error-in-all-my-apps-for-every-call-to-smtp-servers

    0 讨论(0)
  • 2020-12-05 04:55

    You can configure Ubuntu to prefer IPv4 over IPv6. This way you will be able to send emails and access IPv6-only sites. Edit /etc/gai.conf and uncomment the following line:

    precedence ::ffff:0:0/96 100
    
    0 讨论(0)
提交回复
热议问题