Project

General

Profile

Actions

Defect #44765

open

Emails are lost when rdm-mailhandler.rb fails to contact Redmine because of an error such as a DNS failure or a timeout

Defect #44765: Emails are lost when rdm-mailhandler.rb fails to contact Redmine because of an error such as a DNS failure or a timeout

Added by Go MAEDA 1 day ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Email receiving
Resolution:
Affected version:

Description

The attached patch fixes a problem in extra/mail_handler/rdm-mailhandler.rb where incoming emails are lost when the script fails to contact Redmine, for example because of a DNS failure or a timeout.

When the connection to Redmine is refused, the script ends with exit status 75 (EX_TEMPFAIL). The MTA then keeps the email in its queue and delivers it again later.

However, the script does not handle many other errors in this way, because it rescues only SystemCallError and IOError:

begin
  response = Net::HTTPS.post_form(...)
rescue SystemCallError, IOError => e # connection refused, etc.
  warn "An error occurred while contacting your Redmine server: #{e.message}" 
  return 75 # temporary failure
end

For example, the following errors are not rescued, so the script ends with exit status 1:

  • SocketError: the host name of the Redmine server cannot be resolved
  • OpenSSL::SSL::SSLError: a TLS error occurs, for example because the server certificate has expired
  • Net::OpenTimeout and Net::ReadTimeout: Redmine does not respond within 60 seconds
  • Net::HTTPBadResponse: the response is malformed

MTAs treat exit status 1 as a permanent failure and return the email to the sender (a bounce), so the email never reaches Redmine. However, none of these errors is caused by the email itself, and the email can be delivered after the problem is solved.

The patch rescues all errors that are raised while the script sends the email to Redmine, and returns exit status 75 for them in the same way as for a refused connection. Adding the classes above to the rescue clause is not enough, because these errors come from several libraries (socket, OpenSSL, and Net::HTTP) and have no common superclass other than StandardError, so such a list can easily miss some of them.


Files

No data to display

Actions

Also available in: PDF Atom