Defect #40193
closedPerformance issue with email address auto-linking in the default ("none") formatter
0%
Description
We recently encountered a significant issue where a user created issues with very lengthy descriptions, including email addresses at the end. This scenario exposed a performance concern in the auto_mailto!
method, leading to potential server overload and unavailable application.
The issue stems from the fact that the regular expression used in the auto_mailto!
method is relatively slow when applied to large text, posing challenges for improvement.
Attached is a test case that replicates the problem, highlighting that text formatting is swift on extensive input without email addresses, but significantly slows down when the auto_mailto!
method is involved.
To address this issue in our production environment, we've temporarily implemented a patch. While it may not be the most elegant piece of code, it effectively mitigates the problem we encountered. This solution prevents server timeouts when users attempt to render the affected issues:
diff --git a/lib/redmine/wiki_formatting.rb b/lib/redmine/wiki_formatting.rb
index 6bd4d4c3f..be084f43c 100644
--- a/lib/redmine/wiki_formatting.rb
+++ b/lib/redmine/wiki_formatting.rb
@@ -159,6 +159,7 @@ module Redmine
# Destructively replaces email addresses into clickable links
def auto_mailto!(text)
+ return text if text.length > 10000
text.gsub!(/([\w\.!#\$%\-+.\/]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/) do
mail = $1
if /<a\b[^>]*>(.*)(#{Regexp.escape(mail)})(.*)<\/a>/.match?(text)
Files