This is an automated email from the ASF dual-hosted git repository.

rishabhdaim pushed a commit to branch OAK-12300
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git

commit 326724e935b7554fdcfd3e5b62e9f73448c2056b
Author: rishabhdaim <[email protected]>
AuthorDate: Mon Jul 6 21:06:41 2026 +0530

    OAK-XXXXX: Remove ServiceListener after awaitServiceEvent completes
    
    The EventServiceListener was never removed from the BundleContext after
    awaitServiceEvent completed (either successfully or via timeout). This 
caused:
    
    1. Resource leaks - listeners accumulated across test runs
    2. Test interference - listeners from previous tests continued receiving 
events
    3. Intermittent test failures - unrelated service events could be captured,
       causing timeout errors when waiting for specific service events
    
    Fix: Add try-finally block to ensure bundleContext.removeServiceListener()
    is always called after the await completes, preventing listener accumulation
    and cross-test event interference.
    
    Co-authored-by: Copilot <[email protected]>
---
 .../oak/run/osgi/AbstractRepositoryFactoryTest.java        | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git 
a/oak-pojosr/src/test/java/org/apache/jackrabbit/oak/run/osgi/AbstractRepositoryFactoryTest.java
 
b/oak-pojosr/src/test/java/org/apache/jackrabbit/oak/run/osgi/AbstractRepositoryFactoryTest.java
index 3167e9168d..9b2cbd8a9d 100644
--- 
a/oak-pojosr/src/test/java/org/apache/jackrabbit/oak/run/osgi/AbstractRepositoryFactoryTest.java
+++ 
b/oak-pojosr/src/test/java/org/apache/jackrabbit/oak/run/osgi/AbstractRepositoryFactoryTest.java
@@ -194,11 +194,15 @@ public abstract class AbstractRepositoryFactoryTest {
             EventServiceListener listener = new 
EventServiceListener(eventTypes, bundleContext, serviceFilter);
 
             bundleContext.addServiceListener(listener);
-            closure.run();
-            if (!listener.getLatch().await(timeout, timeUnit)) {
-                throw new AssertionError("Exceeded timeout waiting for service 
event matching " +
-                        "[eventTypes: " + eventTypes + ", filter: " + 
serviceFilter + "], " +
-                        "got " + listener.events.size() + " non matching 
events: [" + listener.events + "]");
+            try {
+                closure.run();
+                if (!listener.getLatch().await(timeout, timeUnit)) {
+                    throw new AssertionError("Exceeded timeout waiting for 
service event matching " +
+                            "[eventTypes: " + eventTypes + ", filter: " + 
serviceFilter + "], " +
+                            "got " + listener.events.size() + " non matching 
events: [" + listener.events + "]");
+                }
+            } finally {
+                bundleContext.removeServiceListener(listener);
             }
         } catch (Exception e) {
             throw new RuntimeException(e);

Reply via email to