vy commented on code in PR #3474:
URL: https://github.com/apache/logging-log4j2/pull/3474#discussion_r1977465429


##########
log4j-core/src/main/java/org/apache/logging/log4j/core/util/internal/InternalLoggerRegistry.java:
##########
@@ -53,13 +57,48 @@ public final class InternalLoggerRegistry {
             new WeakHashMap<>();
 
     private final ReadWriteLock lock = new ReentrantReadWriteLock();
-
     private final Lock readLock = lock.readLock();
-
     private final Lock writeLock = lock.writeLock();
 
+    // ReferenceQueue to track stale WeakReferences
+    private final ReferenceQueue<Logger> staleLoggerRefs = new 
ReferenceQueue<>();
+
     public InternalLoggerRegistry() {}
 
+    /**
+     * Expunges stale logger references from the registry.
+     */
+    private void expungeStaleEntries() {
+        Reference<? extends Logger> loggerRef;
+        while ((loggerRef = staleLoggerRefs.poll()) != null) {
+            removeLogger(loggerRef);
+        }

Review Comment:
   @ppkarwasz, you're right. @Suvrat1629, please proceed with the suggestion of 
@ppkarwasz. Though I suggest having double-checking:
   
   ```
   if (!refQueue.isEmpty) {
       lock();
       try {
           if (!refQueue.isEmpty) {
               // Clear `refQueue`
               // Clean up `loggerRefByNameByMessageFactory`
           }
       } finally {
          unlock();
       }
   }
   ```



-- 
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.

To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org

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

Reply via email to