]> source.dussan.org Git - gitblit.git/commitdiff
Fixed MailExecutor's flaws in coping with mail server connection trouble
authorJames Moger <james.moger@gitblit.com>
Thu, 23 Aug 2012 01:59:12 +0000 (21:59 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 23 Aug 2012 01:59:12 +0000 (21:59 -0400)
docs/04_releases.mkd
src/com/gitblit/MailExecutor.java

index fc56876a55951e7a75e830aaee66238fafe68d5a..4331d0a1eed308e8dace2b5d58e66b0092117969 100644 (file)
@@ -11,6 +11,7 @@ If you are updating from an earlier release AND you have indexed branches with t
 \r
 #### fixes\r
 \r
+- Fixed MailExecutor's failure to cope with mail server connection troubles resulting in 100% CPU usage\r
 - Fixed generated urls in Groovy *sendmail* hook script for grouped repositories\r
 - Fixed generated urls in RSS feeds for grouped repositories\r
 - Eliminated an unnecessary reopsitory enumeration call on the root page which should result in faster page loads (issue 103) \r
index 77dc80ba017218cd5002aef6bd57c7020cff0038..ea19edbfeebd7379f03b121ef0b0f3db43d6d299 100644 (file)
@@ -17,7 +17,6 @@ package com.gitblit;
 \r
 import java.util.ArrayList;\r
 import java.util.Arrays;\r
-import java.util.Collections;\r
 import java.util.Date;\r
 import java.util.HashSet;\r
 import java.util.List;\r
@@ -29,7 +28,6 @@ import java.util.regex.Pattern;
 \r
 import javax.mail.Authenticator;\r
 import javax.mail.Message;\r
-import javax.mail.Message.RecipientType;\r
 import javax.mail.PasswordAuthentication;\r
 import javax.mail.Session;\r
 import javax.mail.Transport;\r
@@ -53,8 +51,6 @@ public class MailExecutor implements Runnable {
 \r
        private final Queue<Message> queue = new ConcurrentLinkedQueue<Message>();\r
 \r
-       private final Set<Message> failures = Collections.synchronizedSet(new HashSet<Message>());\r
-\r
        private final Session session;\r
 \r
        private final IStoredSettings settings;\r
@@ -216,49 +212,22 @@ public class MailExecutor implements Runnable {
                if (!queue.isEmpty()) {\r
                        if (session != null) {\r
                                // send message via mail server\r
+                               List<Message> failures = new ArrayList<Message>();\r
                                Message message = null;\r
-                               while ((message = queue.peek()) != null) {\r
+                               while ((message = queue.poll()) != null) {\r
                                        try {\r
                                                if (settings.getBoolean(Keys.mail.debug, false)) {\r
-                                                       logger.info("send: "\r
-                                                                       + StringUtils.trimString(\r
-                                                                                       message.getSubject()\r
-                                                                                                       + " => "\r
-                                                                                                       + message.getRecipients(RecipientType.TO)[0]\r
-                                                                                                                       .toString(), 60));\r
+                                                       logger.info("send: " + StringUtils.trimString(message.getSubject(), 60));\r
                                                }\r
                                                Transport.send(message);\r
-                                               queue.remove();\r
-                                               failures.remove(message);\r
-                                       } catch (Throwable e) {\r
-                                               if (!failures.contains(message)) {\r
-                                                       logger.error("Failed to send message", e);\r
-                                                       failures.add(message);\r
-                                               }\r
-                                       }\r
-                               }\r
-                       }\r
-               } else {\r
-                       // log message to console and drop\r
-                       if (!queue.isEmpty()) {\r
-                               Message message = null;\r
-                               while ((message = queue.peek()) != null) {\r
-                                       try {\r
-                                               logger.info("drop: "\r
-                                                               + StringUtils.trimString(\r
-                                                                               (message.getSubject())\r
-                                                                                               + " => "\r
-                                                                                               + message.getRecipients(RecipientType.TO)[0]\r
-                                                                                                               .toString(), 60));\r
-                                               queue.remove();\r
-                                               failures.remove(message);\r
                                        } catch (Throwable e) {\r
-                                               if (!failures.contains(message)) {\r
-                                                       logger.error("Failed to remove message from queue");\r
-                                                       failures.add(message);\r
-                                               }\r
+                                               logger.error("Failed to send message", e);\r
+                                               failures.add(message);\r
                                        }\r
                                }\r
+                               \r
+                               // push the failures back onto the queue for the next cycle\r
+                               queue.addAll(failures);\r
                        }\r
                }\r
        }\r