You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by jf...@apache.org on 2010/05/20 17:25:13 UTC

svn commit: r946671 - /tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java

Author: jfclere
Date: Thu May 20 15:25:13 2010
New Revision: 946671

URL: http://svn.apache.org/viewvc?rev=946671&view=rev
Log:
Prevent core due to wrong synchronisation.

Modified:
    tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java

Modified: tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java?rev=946671&r1=946670&r2=946671&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java Thu May 20 15:25:13 2010
@@ -72,9 +72,15 @@ public class AprLifecycleListener
     protected static boolean sslAvailable = false;
     protected static boolean aprAvailable = false;
 
+    protected static String lock = "";
+
     public static boolean isAprAvailable() {
         //https://issues.apache.org/bugzilla/show_bug.cgi?id=48613
-        if (instanceCreated) init();
+        if (instanceCreated) {
+            synchronized (lock) {
+                init();
+            }
+        }
         return aprAvailable;
     }
     
@@ -92,28 +98,32 @@ public class AprLifecycleListener
     public void lifecycleEvent(LifecycleEvent event) {
 
         if (Lifecycle.INIT_EVENT.equals(event.getType())) {
-            init();
-            if (aprAvailable) {
-                try {
-                    initializeSSL();
-                } catch (Throwable t) {
-                    log.info(sm.getString("aprListener.sslInit"));
+            synchronized (lock) {
+                init();
+                if (aprAvailable) {
+                    try {
+                        initializeSSL();
+                    } catch (Throwable t) {
+                        log.info(sm.getString("aprListener.sslInit"));
+                    }
                 }
             }
         } else if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType())) {
-            if (!aprAvailable) {
-                return;
-            }
-            try {
-                terminateAPR();
-            } catch (Throwable t) {
-                log.info(sm.getString("aprListener.aprDestroy"));
+            synchronized (lock) {
+                if (!aprAvailable) {
+                    return;
+                }
+                try {
+                    terminateAPR();
+                } catch (Throwable t) {
+                    log.info(sm.getString("aprListener.aprDestroy"));
+                }
             }
         }
 
     }
 
-    private static synchronized void terminateAPR()
+    private static void terminateAPR()
         throws ClassNotFoundException, NoSuchMethodException,
                IllegalAccessException, InvocationTargetException
     {
@@ -121,6 +131,8 @@ public class AprLifecycleListener
         Method method = Class.forName("org.apache.tomcat.jni.Library")
             .getMethod(methodName, (Class [])null);
         method.invoke(null, (Object []) null);
+        aprAvailable = false;
+        aprInitialized = false;
     }
 
     private static void init()
@@ -188,7 +200,7 @@ public class AprLifecycleListener
         aprAvailable = true;
     }
 
-    private static synchronized void initializeSSL()
+    private static void initializeSSL()
         throws ClassNotFoundException, NoSuchMethodException,
                IllegalAccessException, InvocationTargetException
     {



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r946671 - /tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java

Posted by sebb <se...@gmail.com>.
On 20/05/2010, jfclere@apache.org <jf...@apache.org> wrote:
> Author: jfclere
>  Date: Thu May 20 15:25:13 2010
>  New Revision: 946671
>
>  URL: http://svn.apache.org/viewvc?rev=946671&view=rev
>  Log:
>  Prevent core due to wrong synchronisation.
>
>  Modified:
>     tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java

Although the cause of the core dump was that the wrong synch. was
used, it seems to me that the APR code should still protect itself
(and the JVM) against accidental or deliberate misuse.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r946671 - /tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java

Posted by sebb <se...@gmail.com>.
On 20/05/2010, Mark Thomas <ma...@apache.org> wrote:
> On 20/05/2010 16:25, jfclere@apache.org wrote:
>  > Author: jfclere
>  > Date: Thu May 20 15:25:13 2010
>  > New Revision: 946671
>  >
>  > URL: http://svn.apache.org/viewvc?rev=946671&view=rev
>  > Log:
>  > Prevent core due to wrong synchronisation.
>  >
>  > Modified:
>  >     tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java
>  >
>  > Modified: tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java
>  > URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java?rev=946671&r1=946670&r2=946671&view=diff
>  > ==============================================================================
>  > --- tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java (original)
>  > +++ tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java Thu May 20 15:25:13 2010
>  > @@ -72,9 +72,15 @@ public class AprLifecycleListener
>  >      protected static boolean sslAvailable = false;
>  >      protected static boolean aprAvailable = false;
>  >
>  > +    protected static String lock = "";
>  > +
>
>
> Better as:
>
>  protected static Object lock = new Object();

Even better:

  protected static final Object lock = new Object();

otherwise the lock can be subverted.

>
>  Mark
>
>
>  >      public static boolean isAprAvailable() {
>  >          //https://issues.apache.org/bugzilla/show_bug.cgi?id=48613
>  > -        if (instanceCreated) init();
>  > +        if (instanceCreated) {
>  > +            synchronized (lock) {
>  > +                init();
>  > +            }
>  > +        }
>  >          return aprAvailable;
>  >      }
>  >
>  > @@ -92,28 +98,32 @@ public class AprLifecycleListener
>  >      public void lifecycleEvent(LifecycleEvent event) {
>  >
>  >          if (Lifecycle.INIT_EVENT.equals(event.getType())) {
>  > -            init();
>  > -            if (aprAvailable) {
>  > -                try {
>  > -                    initializeSSL();
>  > -                } catch (Throwable t) {
>  > -                    log.info(sm.getString("aprListener.sslInit"));
>  > +            synchronized (lock) {
>  > +                init();
>  > +                if (aprAvailable) {
>  > +                    try {
>  > +                        initializeSSL();
>  > +                    } catch (Throwable t) {
>  > +                        log.info(sm.getString("aprListener.sslInit"));
>  > +                    }
>  >                  }
>  >              }
>  >          } else if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType())) {
>  > -            if (!aprAvailable) {
>  > -                return;
>  > -            }
>  > -            try {
>  > -                terminateAPR();
>  > -            } catch (Throwable t) {
>  > -                log.info(sm.getString("aprListener.aprDestroy"));
>  > +            synchronized (lock) {
>  > +                if (!aprAvailable) {
>  > +                    return;
>  > +                }
>  > +                try {
>  > +                    terminateAPR();
>  > +                } catch (Throwable t) {
>  > +                    log.info(sm.getString("aprListener.aprDestroy"));
>  > +                }
>  >              }
>  >          }
>  >
>  >      }
>  >
>  > -    private static synchronized void terminateAPR()
>  > +    private static void terminateAPR()
>  >          throws ClassNotFoundException, NoSuchMethodException,
>  >                 IllegalAccessException, InvocationTargetException
>  >      {
>  > @@ -121,6 +131,8 @@ public class AprLifecycleListener
>  >          Method method = Class.forName("org.apache.tomcat.jni.Library")
>  >              .getMethod(methodName, (Class [])null);
>  >          method.invoke(null, (Object []) null);
>  > +        aprAvailable = false;
>  > +        aprInitialized = false;
>  >      }
>  >
>  >      private static void init()
>  > @@ -188,7 +200,7 @@ public class AprLifecycleListener
>  >          aprAvailable = true;
>  >      }
>  >
>  > -    private static synchronized void initializeSSL()
>  > +    private static void initializeSSL()
>  >          throws ClassNotFoundException, NoSuchMethodException,
>  >                 IllegalAccessException, InvocationTargetException
>  >      {
>  >
>  >
>  >
>  > ---------------------------------------------------------------------
>  > To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
>  > For additional commands, e-mail: dev-help@tomcat.apache.org
>  >
>
>
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
>  For additional commands, e-mail: dev-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r946671 - /tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java

Posted by Mark Thomas <ma...@apache.org>.
On 20/05/2010 16:25, jfclere@apache.org wrote:
> Author: jfclere
> Date: Thu May 20 15:25:13 2010
> New Revision: 946671
> 
> URL: http://svn.apache.org/viewvc?rev=946671&view=rev
> Log:
> Prevent core due to wrong synchronisation.
> 
> Modified:
>     tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java
> 
> Modified: tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java
> URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java?rev=946671&r1=946670&r2=946671&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java (original)
> +++ tomcat/trunk/java/org/apache/catalina/core/AprLifecycleListener.java Thu May 20 15:25:13 2010
> @@ -72,9 +72,15 @@ public class AprLifecycleListener
>      protected static boolean sslAvailable = false;
>      protected static boolean aprAvailable = false;
>  
> +    protected static String lock = "";
> +

Better as:

protected static Object lock = new Object();

Mark

>      public static boolean isAprAvailable() {
>          //https://issues.apache.org/bugzilla/show_bug.cgi?id=48613
> -        if (instanceCreated) init();
> +        if (instanceCreated) {
> +            synchronized (lock) {
> +                init();
> +            }
> +        }
>          return aprAvailable;
>      }
>      
> @@ -92,28 +98,32 @@ public class AprLifecycleListener
>      public void lifecycleEvent(LifecycleEvent event) {
>  
>          if (Lifecycle.INIT_EVENT.equals(event.getType())) {
> -            init();
> -            if (aprAvailable) {
> -                try {
> -                    initializeSSL();
> -                } catch (Throwable t) {
> -                    log.info(sm.getString("aprListener.sslInit"));
> +            synchronized (lock) {
> +                init();
> +                if (aprAvailable) {
> +                    try {
> +                        initializeSSL();
> +                    } catch (Throwable t) {
> +                        log.info(sm.getString("aprListener.sslInit"));
> +                    }
>                  }
>              }
>          } else if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType())) {
> -            if (!aprAvailable) {
> -                return;
> -            }
> -            try {
> -                terminateAPR();
> -            } catch (Throwable t) {
> -                log.info(sm.getString("aprListener.aprDestroy"));
> +            synchronized (lock) {
> +                if (!aprAvailable) {
> +                    return;
> +                }
> +                try {
> +                    terminateAPR();
> +                } catch (Throwable t) {
> +                    log.info(sm.getString("aprListener.aprDestroy"));
> +                }
>              }
>          }
>  
>      }
>  
> -    private static synchronized void terminateAPR()
> +    private static void terminateAPR()
>          throws ClassNotFoundException, NoSuchMethodException,
>                 IllegalAccessException, InvocationTargetException
>      {
> @@ -121,6 +131,8 @@ public class AprLifecycleListener
>          Method method = Class.forName("org.apache.tomcat.jni.Library")
>              .getMethod(methodName, (Class [])null);
>          method.invoke(null, (Object []) null);
> +        aprAvailable = false;
> +        aprInitialized = false;
>      }
>  
>      private static void init()
> @@ -188,7 +200,7 @@ public class AprLifecycleListener
>          aprAvailable = true;
>      }
>  
> -    private static synchronized void initializeSSL()
> +    private static void initializeSSL()
>          throws ClassNotFoundException, NoSuchMethodException,
>                 IllegalAccessException, InvocationTargetException
>      {
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org