You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by GitBox <gi...@apache.org> on 2020/12/14 08:56:31 UTC

[GitHub] [james-project] jeantil commented on a change in pull request #280: JAMES-3477 demonstrates concurrency issue in MimeMessageCOW

jeantil commented on a change in pull request #280:
URL: https://github.com/apache/james-project/pull/280#discussion_r542206112



##########
File path: server/container/core/src/main/java/org/apache/james/server/core/MimeMessageCopyOnWriteProxy.java
##########
@@ -67,98 +93,208 @@ public MessageReferenceTracker(MimeMessage ref) {
             wrapped = ref;
         }
 
-        protected synchronized void incrementReferenceCount() {
-            referenceCount++;
+        protected void dispose() {
+            ReentrantReadWriteLock.WriteLock writeLock = lock.writeLock();
+            writeLock.lock();
+            try {
+                referenceCount--;
+                if (referenceCount <= 0) {
+                    LifecycleUtil.dispose(wrapped);
+                    wrapped = null;
+                }
+            } finally {
+                writeLock.unlock();
+            }
         }
 
-        protected synchronized void decrementReferenceCount() {
-            referenceCount--;
-            if (referenceCount <= 0) {
-                LifecycleUtil.dispose(wrapped);
-                wrapped = null;
+        protected void incrementReferences() {
+            ReentrantReadWriteLock.WriteLock writeLock = lock.writeLock();
+            writeLock.lock();
+            try {
+                referenceCount++;

Review comment:
       out of curiosity: what meaningful exception could possibly be thrown here ?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org