You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by GitBox <gi...@apache.org> on 2021/07/19 18:27:57 UTC

[GitHub] [solr] madrob opened a new pull request #227: SOLR-15550 Save submitter trace in ObjectReleaseTracker

madrob opened a new pull request #227:
URL: https://github.com/apache/solr/pull/227


   https://issues.apache.org/jira/browse/SOLR-15550
   
   Example logging available on the JIRA issue.


-- 
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: issues-unsubscribe@solr.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] madrob commented on a change in pull request #227: SOLR-15550 Save submitter trace in ObjectReleaseTracker

Posted by GitBox <gi...@apache.org>.
madrob commented on a change in pull request #227:
URL: https://github.com/apache/solr/pull/227#discussion_r673288008



##########
File path: solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
##########
@@ -196,7 +198,13 @@ public void execute(final Runnable command) {
 
       String ctxStr = contextString.toString().replace("/", "//");
       final String submitterContextStr = ctxStr.length() <= MAX_THREAD_NAME_LEN ? ctxStr : ctxStr.substring(0, MAX_THREAD_NAME_LEN);
-      final Exception submitterStackTrace = enableSubmitterStackTrace ? new Exception("Submitter stack trace") : null;
+      final Exception submitterStackTrace;

Review comment:
       No specific reason, I assume Exception is just the default for a lot of people and less cognitive burden when reading it.




-- 
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: issues-unsubscribe@solr.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] dsmiley commented on a change in pull request #227: SOLR-15550 Save submitter trace in ObjectReleaseTracker

Posted by GitBox <gi...@apache.org>.
dsmiley commented on a change in pull request #227:
URL: https://github.com/apache/solr/pull/227#discussion_r672789135



##########
File path: solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
##########
@@ -196,7 +198,13 @@ public void execute(final Runnable command) {
 
       String ctxStr = contextString.toString().replace("/", "//");
       final String submitterContextStr = ctxStr.length() <= MAX_THREAD_NAME_LEN ? ctxStr : ctxStr.substring(0, MAX_THREAD_NAME_LEN);
-      final Exception submitterStackTrace = enableSubmitterStackTrace ? new Exception("Submitter stack trace") : null;
+      final Exception submitterStackTrace;
+      if (enableSubmitterStackTrace) {
+        Exception grandParentSubmitter = submitter.get();
+        submitterStackTrace = new Exception("Submitter stack trace", grandParentSubmitter);

Review comment:
       Ah nevermind 👍 




-- 
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: issues-unsubscribe@solr.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] sonatype-lift[bot] commented on a change in pull request #227: SOLR-15550 Save submitter trace in ObjectReleaseTracker

Posted by GitBox <gi...@apache.org>.
sonatype-lift[bot] commented on a change in pull request #227:
URL: https://github.com/apache/solr/pull/227#discussion_r673387063



##########
File path: solr/solrj/src/java/org/apache/solr/common/util/ObjectReleaseTracker.java
##########
@@ -57,49 +55,55 @@ public static void clear() {
    * @return null if ok else error message
    */
   public static String checkEmpty() {
-    String error = null;
-    Set<Entry<Object,String>> entries = OBJECTS.entrySet();
+    if (OBJECTS.isEmpty()) {
+      return null;
+    }
 
-    if (entries.size() > 0) {
-      List<String> objects = new ArrayList<>();
-      for (Entry<Object,String> entry : entries) {
-        objects.add(entry.getKey().getClass().getSimpleName());
-      }
-      
-      error = "ObjectTracker found " + entries.size() + " object(s) that were not released!!! " + objects + "\n";
-      for (Entry<Object,String> entry : entries) {
-        error += entry.getValue() + "\n";
-      }
+    StringBuilder error = new StringBuilder();
+    error.append("ObjectTracker found ").append(OBJECTS.size()).append(" object(s) that were not released!!! ");
+
+    Set<Entry<Object, Exception>> entries = OBJECTS.entrySet();
+
+    ArrayList<String> objects = new ArrayList<>(OBJECTS.size());
+    for (Object object : OBJECTS.keySet()) {
+      Class<?> clazz = object.getClass();
+      objects.add(clazz.isAnonymousClass() ? clazz.getSuperclass().getSimpleName() : clazz.getSimpleName());
+    }
+    error.append(objects).append("\n");
+
+    for (Entry<Object, Exception> entry : entries) {
+      StringWriter sw = new StringWriter();
+      PrintWriter pw = new PrintWriter(sw);
+      entry.getValue().printStackTrace(pw);

Review comment:
       *INFORMATION_EXPOSURE_THROUGH_AN_ERROR_MESSAGE:*  Possible information exposure through an error message [(details)](https://find-sec-bugs.github.io/bugs.htm#INFORMATION_EXPOSURE_THROUGH_AN_ERROR_MESSAGE)
   (at-me [in a reply](https://help.sonatype.com/lift) with `help` or `ignore`)




-- 
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: issues-unsubscribe@solr.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] madrob commented on a change in pull request #227: SOLR-15550 Save submitter trace in ObjectReleaseTracker

Posted by GitBox <gi...@apache.org>.
madrob commented on a change in pull request #227:
URL: https://github.com/apache/solr/pull/227#discussion_r673477241



##########
File path: solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
##########
@@ -196,7 +198,13 @@ public void execute(final Runnable command) {
 
       String ctxStr = contextString.toString().replace("/", "//");
       final String submitterContextStr = ctxStr.length() <= MAX_THREAD_NAME_LEN ? ctxStr : ctxStr.substring(0, MAX_THREAD_NAME_LEN);
-      final Exception submitterStackTrace = enableSubmitterStackTrace ? new Exception("Submitter stack trace") : null;
+      final Exception submitterStackTrace;
+      if (enableSubmitterStackTrace) {
+        Exception grandParentSubmitter = submitter.get();
+        submitterStackTrace = new Exception("Submitter stack trace", grandParentSubmitter);

Review comment:
       I added a test for this to demonstrate what is happening, not sure if that made things more clear or added to the confusion. Can you take a look at it and then let me know what kind of comments you think are useful 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.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] dsmiley commented on a change in pull request #227: SOLR-15550 Save submitter trace in ObjectReleaseTracker

Posted by GitBox <gi...@apache.org>.
dsmiley commented on a change in pull request #227:
URL: https://github.com/apache/solr/pull/227#discussion_r672780636



##########
File path: solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
##########
@@ -196,7 +198,13 @@ public void execute(final Runnable command) {
 
       String ctxStr = contextString.toString().replace("/", "//");
       final String submitterContextStr = ctxStr.length() <= MAX_THREAD_NAME_LEN ? ctxStr : ctxStr.substring(0, MAX_THREAD_NAME_LEN);
-      final Exception submitterStackTrace = enableSubmitterStackTrace ? new Exception("Submitter stack trace") : null;
+      final Exception submitterStackTrace;
+      if (enableSubmitterStackTrace) {
+        Exception grandParentSubmitter = submitter.get();
+        submitterStackTrace = new Exception("Submitter stack trace", grandParentSubmitter);

Review comment:
       Hmm; isn't this one of those cases we should call fillInStackTrace() on the exception because we don't throw it?




-- 
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: issues-unsubscribe@solr.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] madrob commented on a change in pull request #227: SOLR-15550 Save submitter trace in ObjectReleaseTracker

Posted by GitBox <gi...@apache.org>.
madrob commented on a change in pull request #227:
URL: https://github.com/apache/solr/pull/227#discussion_r672783290



##########
File path: solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
##########
@@ -196,7 +198,13 @@ public void execute(final Runnable command) {
 
       String ctxStr = contextString.toString().replace("/", "//");
       final String submitterContextStr = ctxStr.length() <= MAX_THREAD_NAME_LEN ? ctxStr : ctxStr.substring(0, MAX_THREAD_NAME_LEN);
-      final Exception submitterStackTrace = enableSubmitterStackTrace ? new Exception("Submitter stack trace") : null;
+      final Exception submitterStackTrace;
+      if (enableSubmitterStackTrace) {
+        Exception grandParentSubmitter = submitter.get();
+        submitterStackTrace = new Exception("Submitter stack trace", grandParentSubmitter);

Review comment:
       I don't understand the suggestion - Throwable's constructor already calls it for us.




-- 
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: issues-unsubscribe@solr.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] madrob merged pull request #227: SOLR-15550 Save submitter trace in ObjectReleaseTracker

Posted by GitBox <gi...@apache.org>.
madrob merged pull request #227:
URL: https://github.com/apache/solr/pull/227


   


-- 
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: issues-unsubscribe@solr.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] dsmiley commented on a change in pull request #227: SOLR-15550 Save submitter trace in ObjectReleaseTracker

Posted by GitBox <gi...@apache.org>.
dsmiley commented on a change in pull request #227:
URL: https://github.com/apache/solr/pull/227#discussion_r672789251



##########
File path: solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
##########
@@ -196,7 +198,13 @@ public void execute(final Runnable command) {
 
       String ctxStr = contextString.toString().replace("/", "//");
       final String submitterContextStr = ctxStr.length() <= MAX_THREAD_NAME_LEN ? ctxStr : ctxStr.substring(0, MAX_THREAD_NAME_LEN);
-      final Exception submitterStackTrace = enableSubmitterStackTrace ? new Exception("Submitter stack trace") : null;
+      final Exception submitterStackTrace;

Review comment:
       Why create Exception specifically -- why not do Throwable?




-- 
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: issues-unsubscribe@solr.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] madrob commented on a change in pull request #227: SOLR-15550 Save submitter trace in ObjectReleaseTracker

Posted by GitBox <gi...@apache.org>.
madrob commented on a change in pull request #227:
URL: https://github.com/apache/solr/pull/227#discussion_r674165749



##########
File path: solr/core/src/test/org/apache/solr/util/TestObjectReleaseTracker.java
##########
@@ -16,46 +16,103 @@
  */
 package org.apache.solr.util;
 
-import org.apache.lucene.util.TestRuleLimitSysouts.Limit;
 import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.util.ExecutorUtil;
 import org.apache.solr.common.util.ObjectReleaseTracker;
+import org.apache.solr.common.util.SolrNamedThreadFactory;
+import org.hamcrest.MatcherAssert;
 import org.junit.Test;
 
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.hamcrest.Matchers.containsString;
 
-@Limit(bytes=150000) // raise limit as this writes to sys err
 public class TestObjectReleaseTracker extends SolrTestCaseJ4 {
-  
+
   @Test
-  public void testObjectReleaseTracker() {
-    ObjectReleaseTracker.track(new Object());
-    ObjectReleaseTracker.release(new Object());
-    assertNotNull(SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1));
-    assertNull(SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1));
+  public void testReleaseObject() {
     Object obj = new Object();
     ObjectReleaseTracker.track(obj);
     ObjectReleaseTracker.release(obj);
     assertNull(SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1));
-    
+
     Object obj1 = new Object();
     ObjectReleaseTracker.track(obj1);
     Object obj2 = new Object();
     ObjectReleaseTracker.track(obj2);
     Object obj3 = new Object();
     ObjectReleaseTracker.track(obj3);
-    
+
     ObjectReleaseTracker.release(obj1);
     ObjectReleaseTracker.release(obj2);
     ObjectReleaseTracker.release(obj3);
     assertNull(SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1));
-    
+  }
+
+  @Test
+  public void testUnreleased() {
+    Object obj1 = new Object();
+    Object obj2 = new Object();
+    Object obj3 = new Object();
+
     ObjectReleaseTracker.track(obj1);
     ObjectReleaseTracker.track(obj2);
     ObjectReleaseTracker.track(obj3);
     
     ObjectReleaseTracker.release(obj1);
     ObjectReleaseTracker.release(obj2);
     // ObjectReleaseTracker.release(obj3);
+
     assertNotNull(SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1));
     assertNull(SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1));
   }
+
+  @Test
+  public void testReleaseDifferentObject() {
+    ObjectReleaseTracker.track(new Object());
+    ObjectReleaseTracker.release(new Object());
+    assertNotNull(SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1));
+    assertNull(SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1));
+  }
+
+  @Test
+  public void testAnonymousClasses() {
+    ObjectReleaseTracker.track(new Object() {});
+    String message = SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1);
+    MatcherAssert.assertThat(message, containsString("[Object]"));
+  }
+
+  @Test
+  public void testAsyncTracking() throws InterruptedException, ExecutionException {
+    ExecutorService es = ExecutorUtil.newMDCAwareSingleThreadExecutor(new SolrNamedThreadFactory("TestExecutor"));
+    Object trackable = new Object();
+
+    Future<?> result = es.submit(() -> {
+      ObjectReleaseTracker.track(trackable);
+    });
+
+    result.get(); // make sure that track has been called
+    String message = SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1);
+    MatcherAssert.assertThat(message, containsString(getTestName()));

Review comment:
       Based on your commit, I realized I wasn't testing what I thought I was testing, so I tried a slightly different set of criteria.




-- 
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: issues-unsubscribe@solr.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] dsmiley commented on a change in pull request #227: SOLR-15550 Save submitter trace in ObjectReleaseTracker

Posted by GitBox <gi...@apache.org>.
dsmiley commented on a change in pull request #227:
URL: https://github.com/apache/solr/pull/227#discussion_r672780636



##########
File path: solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
##########
@@ -196,7 +198,13 @@ public void execute(final Runnable command) {
 
       String ctxStr = contextString.toString().replace("/", "//");
       final String submitterContextStr = ctxStr.length() <= MAX_THREAD_NAME_LEN ? ctxStr : ctxStr.substring(0, MAX_THREAD_NAME_LEN);
-      final Exception submitterStackTrace = enableSubmitterStackTrace ? new Exception("Submitter stack trace") : null;
+      final Exception submitterStackTrace;
+      if (enableSubmitterStackTrace) {
+        Exception grandParentSubmitter = submitter.get();
+        submitterStackTrace = new Exception("Submitter stack trace", grandParentSubmitter);

Review comment:
       Hmm; isn't this one of those cases we should call fillInStackTrace() on the exception because we don't throw it?

##########
File path: solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
##########
@@ -196,7 +198,13 @@ public void execute(final Runnable command) {
 
       String ctxStr = contextString.toString().replace("/", "//");
       final String submitterContextStr = ctxStr.length() <= MAX_THREAD_NAME_LEN ? ctxStr : ctxStr.substring(0, MAX_THREAD_NAME_LEN);
-      final Exception submitterStackTrace = enableSubmitterStackTrace ? new Exception("Submitter stack trace") : null;
+      final Exception submitterStackTrace;
+      if (enableSubmitterStackTrace) {
+        Exception grandParentSubmitter = submitter.get();
+        submitterStackTrace = new Exception("Submitter stack trace", grandParentSubmitter);

Review comment:
       Ah nevermind 👍 

##########
File path: solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
##########
@@ -196,7 +198,13 @@ public void execute(final Runnable command) {
 
       String ctxStr = contextString.toString().replace("/", "//");
       final String submitterContextStr = ctxStr.length() <= MAX_THREAD_NAME_LEN ? ctxStr : ctxStr.substring(0, MAX_THREAD_NAME_LEN);
-      final Exception submitterStackTrace = enableSubmitterStackTrace ? new Exception("Submitter stack trace") : null;
+      final Exception submitterStackTrace;

Review comment:
       Why create Exception specifically -- why not do Throwable?




-- 
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: issues-unsubscribe@solr.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] madrob commented on a change in pull request #227: SOLR-15550 Save submitter trace in ObjectReleaseTracker

Posted by GitBox <gi...@apache.org>.
madrob commented on a change in pull request #227:
URL: https://github.com/apache/solr/pull/227#discussion_r672783290



##########
File path: solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
##########
@@ -196,7 +198,13 @@ public void execute(final Runnable command) {
 
       String ctxStr = contextString.toString().replace("/", "//");
       final String submitterContextStr = ctxStr.length() <= MAX_THREAD_NAME_LEN ? ctxStr : ctxStr.substring(0, MAX_THREAD_NAME_LEN);
-      final Exception submitterStackTrace = enableSubmitterStackTrace ? new Exception("Submitter stack trace") : null;
+      final Exception submitterStackTrace;
+      if (enableSubmitterStackTrace) {
+        Exception grandParentSubmitter = submitter.get();
+        submitterStackTrace = new Exception("Submitter stack trace", grandParentSubmitter);

Review comment:
       I don't understand the suggestion - Throwable's constructor already calls it for us.




-- 
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: issues-unsubscribe@solr.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] cpoerschke commented on a change in pull request #227: SOLR-15550 Save submitter trace in ObjectReleaseTracker

Posted by GitBox <gi...@apache.org>.
cpoerschke commented on a change in pull request #227:
URL: https://github.com/apache/solr/pull/227#discussion_r674076231



##########
File path: solr/core/src/test/org/apache/solr/util/TestObjectReleaseTracker.java
##########
@@ -16,46 +16,103 @@
  */
 package org.apache.solr.util;
 
-import org.apache.lucene.util.TestRuleLimitSysouts.Limit;
 import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.util.ExecutorUtil;
 import org.apache.solr.common.util.ObjectReleaseTracker;
+import org.apache.solr.common.util.SolrNamedThreadFactory;
+import org.hamcrest.MatcherAssert;
 import org.junit.Test;
 
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.hamcrest.Matchers.containsString;
 
-@Limit(bytes=150000) // raise limit as this writes to sys err
 public class TestObjectReleaseTracker extends SolrTestCaseJ4 {
-  
+
   @Test
-  public void testObjectReleaseTracker() {
-    ObjectReleaseTracker.track(new Object());
-    ObjectReleaseTracker.release(new Object());
-    assertNotNull(SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1));
-    assertNull(SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1));
+  public void testReleaseObject() {
     Object obj = new Object();
     ObjectReleaseTracker.track(obj);
     ObjectReleaseTracker.release(obj);
     assertNull(SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1));
-    
+
     Object obj1 = new Object();
     ObjectReleaseTracker.track(obj1);
     Object obj2 = new Object();
     ObjectReleaseTracker.track(obj2);
     Object obj3 = new Object();
     ObjectReleaseTracker.track(obj3);
-    
+
     ObjectReleaseTracker.release(obj1);
     ObjectReleaseTracker.release(obj2);
     ObjectReleaseTracker.release(obj3);
     assertNull(SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1));
-    
+  }
+
+  @Test
+  public void testUnreleased() {
+    Object obj1 = new Object();
+    Object obj2 = new Object();
+    Object obj3 = new Object();
+
     ObjectReleaseTracker.track(obj1);
     ObjectReleaseTracker.track(obj2);
     ObjectReleaseTracker.track(obj3);
     
     ObjectReleaseTracker.release(obj1);
     ObjectReleaseTracker.release(obj2);
     // ObjectReleaseTracker.release(obj3);
+
     assertNotNull(SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1));
     assertNull(SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1));
   }
+
+  @Test
+  public void testReleaseDifferentObject() {
+    ObjectReleaseTracker.track(new Object());
+    ObjectReleaseTracker.release(new Object());
+    assertNotNull(SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1));
+    assertNull(SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1));
+  }
+
+  @Test
+  public void testAnonymousClasses() {
+    ObjectReleaseTracker.track(new Object() {});
+    String message = SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1);
+    MatcherAssert.assertThat(message, containsString("[Object]"));
+  }
+
+  @Test
+  public void testAsyncTracking() throws InterruptedException, ExecutionException {
+    ExecutorService es = ExecutorUtil.newMDCAwareSingleThreadExecutor(new SolrNamedThreadFactory("TestExecutor"));
+    Object trackable = new Object();
+
+    Future<?> result = es.submit(() -> {
+      ObjectReleaseTracker.track(trackable);
+    });
+
+    result.get(); // make sure that track has been called
+    String message = SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1);
+    MatcherAssert.assertThat(message, containsString(getTestName()));

Review comment:
       We could perhaps also test here that the async details are captured too. I'll add a small commit, feel free to revert or amend.

##########
File path: solr/core/src/test/org/apache/solr/util/TestObjectReleaseTracker.java
##########
@@ -16,46 +16,103 @@
  */
 package org.apache.solr.util;
 
-import org.apache.lucene.util.TestRuleLimitSysouts.Limit;
 import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.util.ExecutorUtil;
 import org.apache.solr.common.util.ObjectReleaseTracker;
+import org.apache.solr.common.util.SolrNamedThreadFactory;
+import org.hamcrest.MatcherAssert;
 import org.junit.Test;
 
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.hamcrest.Matchers.containsString;
 
-@Limit(bytes=150000) // raise limit as this writes to sys err
 public class TestObjectReleaseTracker extends SolrTestCaseJ4 {
-  
+
   @Test
-  public void testObjectReleaseTracker() {
-    ObjectReleaseTracker.track(new Object());
-    ObjectReleaseTracker.release(new Object());
-    assertNotNull(SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1));
-    assertNull(SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1));
+  public void testReleaseObject() {
     Object obj = new Object();
     ObjectReleaseTracker.track(obj);
     ObjectReleaseTracker.release(obj);
     assertNull(SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1));
-    
+
     Object obj1 = new Object();
     ObjectReleaseTracker.track(obj1);
     Object obj2 = new Object();
     ObjectReleaseTracker.track(obj2);
     Object obj3 = new Object();
     ObjectReleaseTracker.track(obj3);
-    
+
     ObjectReleaseTracker.release(obj1);
     ObjectReleaseTracker.release(obj2);
     ObjectReleaseTracker.release(obj3);
     assertNull(SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1));
-    
+  }
+
+  @Test
+  public void testUnreleased() {
+    Object obj1 = new Object();
+    Object obj2 = new Object();
+    Object obj3 = new Object();
+
     ObjectReleaseTracker.track(obj1);
     ObjectReleaseTracker.track(obj2);
     ObjectReleaseTracker.track(obj3);
     
     ObjectReleaseTracker.release(obj1);
     ObjectReleaseTracker.release(obj2);
     // ObjectReleaseTracker.release(obj3);
+
     assertNotNull(SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1));
     assertNull(SolrTestCaseJ4.clearObjectTrackerAndCheckEmpty(1));

Review comment:
       Not directly related to the pull request changes here but I wonder if at https://github.com/apache/lucene-solr/blob/releases/lucene-solr/8.9.0/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java#L433 the info logging might be `if (retries > 0)` qualified i.e. the "Done waiting" is only applicable if there was a "Waiting for all" to start with.
   
   Or turning the `break` into a `return` at https://github.com/apache/lucene-solr/blob/releases/lucene-solr/8.9.0/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java#L413 would have the same effect (assuming there's no additional track call happening after the break and before the clear at line 435).

##########
File path: solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
##########
@@ -196,7 +198,13 @@ public void execute(final Runnable command) {
 
       String ctxStr = contextString.toString().replace("/", "//");
       final String submitterContextStr = ctxStr.length() <= MAX_THREAD_NAME_LEN ? ctxStr : ctxStr.substring(0, MAX_THREAD_NAME_LEN);
-      final Exception submitterStackTrace = enableSubmitterStackTrace ? new Exception("Submitter stack trace") : null;
+      final Exception submitterStackTrace;
+      if (enableSubmitterStackTrace) {
+        Exception grandParentSubmitter = submitter.get();
+        submitterStackTrace = new Exception("Submitter stack trace", grandParentSubmitter);

Review comment:
       Hmm, yes, the tests help to demonstrate what is happening. But explaining it in a comment, well, that is trickier and so yes `grandParentSubmitter` is concise and comments as well might just add confusion.




-- 
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: issues-unsubscribe@solr.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] cpoerschke commented on a change in pull request #227: SOLR-15550 Save submitter trace in ObjectReleaseTracker

Posted by GitBox <gi...@apache.org>.
cpoerschke commented on a change in pull request #227:
URL: https://github.com/apache/solr/pull/227#discussion_r673293571



##########
File path: solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
##########
@@ -148,6 +148,8 @@ public static ExecutorService newMDCAwareCachedThreadPool(int maxThreads, Thread
         threadFactory);
   }
 
+  public final static ThreadLocal<Exception> submitter = new ThreadLocal<>();

Review comment:
       ```suggestion
     final static ThreadLocal<Exception> submitter = new ThreadLocal<>();
   ```

##########
File path: solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
##########
@@ -196,7 +198,13 @@ public void execute(final Runnable command) {
 
       String ctxStr = contextString.toString().replace("/", "//");
       final String submitterContextStr = ctxStr.length() <= MAX_THREAD_NAME_LEN ? ctxStr : ctxStr.substring(0, MAX_THREAD_NAME_LEN);
-      final Exception submitterStackTrace = enableSubmitterStackTrace ? new Exception("Submitter stack trace") : null;
+      final Exception submitterStackTrace;
+      if (enableSubmitterStackTrace) {
+        Exception grandParentSubmitter = submitter.get();
+        submitterStackTrace = new Exception("Submitter stack trace", grandParentSubmitter);

Review comment:
       Could we have a comment (or rename) w.r.t. the `grandParent` bit here?
   
   At a glance `parent` is intuitive with the `get/construct/set` pattern. On second glance it seems the current method executes the `submitter.set` call in a pool, making this method the "parent" relative to the pool execution and the `submitter.get` result the "parent" relative to this method but the "grand parent" relative to the method that will run in the pool. Is that it, more or less?




-- 
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: issues-unsubscribe@solr.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] madrob commented on a change in pull request #227: SOLR-15550 Save submitter trace in ObjectReleaseTracker

Posted by GitBox <gi...@apache.org>.
madrob commented on a change in pull request #227:
URL: https://github.com/apache/solr/pull/227#discussion_r672783290



##########
File path: solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
##########
@@ -196,7 +198,13 @@ public void execute(final Runnable command) {
 
       String ctxStr = contextString.toString().replace("/", "//");
       final String submitterContextStr = ctxStr.length() <= MAX_THREAD_NAME_LEN ? ctxStr : ctxStr.substring(0, MAX_THREAD_NAME_LEN);
-      final Exception submitterStackTrace = enableSubmitterStackTrace ? new Exception("Submitter stack trace") : null;
+      final Exception submitterStackTrace;
+      if (enableSubmitterStackTrace) {
+        Exception grandParentSubmitter = submitter.get();
+        submitterStackTrace = new Exception("Submitter stack trace", grandParentSubmitter);

Review comment:
       I don't understand the suggestion - Throwable's constructor already calls it for us.




-- 
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: issues-unsubscribe@solr.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] dsmiley commented on a change in pull request #227: SOLR-15550 Save submitter trace in ObjectReleaseTracker

Posted by GitBox <gi...@apache.org>.
dsmiley commented on a change in pull request #227:
URL: https://github.com/apache/solr/pull/227#discussion_r672780636



##########
File path: solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
##########
@@ -196,7 +198,13 @@ public void execute(final Runnable command) {
 
       String ctxStr = contextString.toString().replace("/", "//");
       final String submitterContextStr = ctxStr.length() <= MAX_THREAD_NAME_LEN ? ctxStr : ctxStr.substring(0, MAX_THREAD_NAME_LEN);
-      final Exception submitterStackTrace = enableSubmitterStackTrace ? new Exception("Submitter stack trace") : null;
+      final Exception submitterStackTrace;
+      if (enableSubmitterStackTrace) {
+        Exception grandParentSubmitter = submitter.get();
+        submitterStackTrace = new Exception("Submitter stack trace", grandParentSubmitter);

Review comment:
       Hmm; isn't this one of those cases we should call fillInStackTrace() on the exception because we don't throw it?

##########
File path: solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
##########
@@ -196,7 +198,13 @@ public void execute(final Runnable command) {
 
       String ctxStr = contextString.toString().replace("/", "//");
       final String submitterContextStr = ctxStr.length() <= MAX_THREAD_NAME_LEN ? ctxStr : ctxStr.substring(0, MAX_THREAD_NAME_LEN);
-      final Exception submitterStackTrace = enableSubmitterStackTrace ? new Exception("Submitter stack trace") : null;
+      final Exception submitterStackTrace;
+      if (enableSubmitterStackTrace) {
+        Exception grandParentSubmitter = submitter.get();
+        submitterStackTrace = new Exception("Submitter stack trace", grandParentSubmitter);

Review comment:
       Ah nevermind 👍 

##########
File path: solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
##########
@@ -196,7 +198,13 @@ public void execute(final Runnable command) {
 
       String ctxStr = contextString.toString().replace("/", "//");
       final String submitterContextStr = ctxStr.length() <= MAX_THREAD_NAME_LEN ? ctxStr : ctxStr.substring(0, MAX_THREAD_NAME_LEN);
-      final Exception submitterStackTrace = enableSubmitterStackTrace ? new Exception("Submitter stack trace") : null;
+      final Exception submitterStackTrace;

Review comment:
       Why create Exception specifically -- why not do Throwable?




-- 
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: issues-unsubscribe@solr.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org