You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2018/08/08 09:49:11 UTC

[sling-org-apache-sling-jcr-base] branch master updated (0b44cad -> 3de2b9f)

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

rombert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-base.git.


    from 0b44cad  Updating badges for org-apache-sling-jcr-base
     new 6f5771a  SLING-7811 - NPE when repository is starting up
     new 3de2b9f  SLING-7811 - NPE when repository is starting up

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../jcr/base/AbstractSlingRepositoryManager.java   | 33 ++++++++++++++++++++--
 1 file changed, 30 insertions(+), 3 deletions(-)


[sling-org-apache-sling-jcr-base] 02/02: SLING-7811 - NPE when repository is starting up

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-base.git

commit 3de2b9f6258bb3dda6bf3cfcf9c39a531fbcc020
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Wed Aug 8 12:42:31 2018 +0300

    SLING-7811 - NPE when repository is starting up
    
    Make sure that each repository startup thread has an individual name.
    This makes it easier to distinguish repository restart issues during
    startup.
---
 .../org/apache/sling/jcr/base/AbstractSlingRepositoryManager.java     | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepositoryManager.java b/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepositoryManager.java
index bedb9e7..002d8bc 100644
--- a/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepositoryManager.java
+++ b/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepositoryManager.java
@@ -85,6 +85,8 @@ import org.slf4j.LoggerFactory;
 @ProviderType
 public abstract class AbstractSlingRepositoryManager {
 
+    private static final AtomicInteger startupCounter = new AtomicInteger();
+
     /** default log */
     private final Logger log = LoggerFactory.getLogger(getClass());
 
@@ -452,7 +454,7 @@ public abstract class AbstractSlingRepositoryManager {
         // start repository asynchronously to allow LoginAdminWhitelist to become available
         // NOTE: making this conditional allows tests to register a mock whitelist before
         // activating the RepositoryManager, so they don't need to deal with async startup
-        startupThread = new Thread("Apache Sling Repository Startup Thread") {
+        startupThread = new Thread("Apache Sling Repository Startup Thread #" + startupCounter.incrementAndGet()) {
             @Override
             public void run() {
                 try {


[sling-org-apache-sling-jcr-base] 01/02: SLING-7811 - NPE when repository is starting up

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-base.git

commit 6f5771acf4b943840c477a8621e54c43a3497b97
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Wed Aug 8 12:40:03 2018 +0300

    SLING-7811 - NPE when repository is starting up
    
    Make the repository initialisation and startup process more robust
    against restarts.
    
    It is possible that while a the repository startup is happening in an
    async manner in the "Apache Sling Repository Startup Thread" a stop is
    requested. This thread should be notified of any stop requests and
    gracefully handle the shutdown.
---
 .../jcr/base/AbstractSlingRepositoryManager.java   | 31 +++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepositoryManager.java b/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepositoryManager.java
index bdbdcbc..bedb9e7 100644
--- a/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepositoryManager.java
+++ b/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepositoryManager.java
@@ -23,6 +23,7 @@ import java.util.Arrays;
 import java.util.Dictionary;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import javax.jcr.Repository;
 
@@ -109,6 +110,10 @@ public abstract class AbstractSlingRepositoryManager {
 
     private final Object repoInitLock = new Object();
 
+    private volatile Thread startupThread;
+
+    private volatile boolean stopRequested;
+
     /**
      * Returns the default workspace, which may be <code>null</code> meaning to
      * use the repository provided default workspace.
@@ -447,17 +452,20 @@ public abstract class AbstractSlingRepositoryManager {
         // start repository asynchronously to allow LoginAdminWhitelist to become available
         // NOTE: making this conditional allows tests to register a mock whitelist before
         // activating the RepositoryManager, so they don't need to deal with async startup
-        new Thread("Apache Sling Repository Startup Thread") {
+        startupThread = new Thread("Apache Sling Repository Startup Thread") {
             @Override
             public void run() {
                 try {
                     waitForWhitelist.await();
                     initializeAndRegisterRepositoryService();
                 } catch (InterruptedException e) {
-                    throw new RuntimeException("Interrupted while waiting for LoginAdminWhitelist", e);
+                    log.info("Interrupted while waiting for the {} service, cancelling repository initialisation", LoginAdminWhitelist.class.getSimpleName(), e);
+                    Thread.currentThread().interrupt();
+                    return;
                 }
             }
-        }.start();
+        };
+        startupThread.start();
     }
 
     private boolean isRepositoryServiceRegistered() {
@@ -474,6 +482,11 @@ public abstract class AbstractSlingRepositoryManager {
                 // ensure we really have the repository
                 log.debug("start: got a Repository");
                 this.repository = newRepo;
+                if ( stopRequested ) {
+                    log.debug("Stop requested, cancelling initialisation and stopping repository");
+                    stop();
+                    return;
+                }
                 synchronized ( this.repoInitLock ) {
                     this.masterSlingRepository = this.create(this.bundleContext.getBundle());
 
@@ -547,6 +560,18 @@ public abstract class AbstractSlingRepositoryManager {
      */
     protected final void stop() {
 
+        stopRequested = true;
+        if ( startupThread != null && startupThread != Thread.currentThread() ) {
+            try {
+                startupThread.interrupt();
+                startupThread.join();
+            } catch (InterruptedException e) {
+                log.debug("Interrupted while waiting for the " + startupThread.getName() + " to complete.", e);
+                Thread.currentThread().interrupt();
+            }
+            startupThread = null;
+        }
+
         // ensure the repository is really disposed off
         if (repository != null || isRepositoryServiceRegistered()) {
             log.info("stop: Repository still running, forcing shutdown");