Liferay module (OSGi package) remains in "Stopping"

Sometimes when I stop my Liferay module (for example, when I put a new version of the JAR in deploy/

) the module refuses to stop.

While the module should go into the "Allowed" state, it will remain in the "Stop" state forever:

OSGi life cycle

This is usually because the thread is not stalled anywhere, or the network connection is not closed properly and it is often painful to explore.

My question . How can you more effectively know if this is a problem with the Liferay module?

What I have tried:

  • The Gogo Shell diag <module id>

    doesn't seem to contain any valuable information about why the module is refusing to leave the Stop state.
  • jstack outputs thousands of lines, the vast majority of which are outside of the Liferay module in question. If there was a way to show jstack information just for my module, that would be great.
+3


source to share


2 answers


First find the PID of your webapp server:

ps aux | grep tomcat

      

Adapt the command if you are using a different server than tomcat, or if you have multiple instances.

Then dump all streams from this server to a file:

jstack 12345 > jstack.txt

      

Where 12345 is the PID you found in the first step.

Then look at the source code for your package and find the service activator. It usually looks like this:

package fr.free.nrw;

[import section]

public class ServiceActivator implements BundleActivator {

    private ServiceRegistration registration;

    @Override
    public void start(BundleContext context) throws Exception {
        registration = context.registerService(
            MyService.class.getName(), new MyServiceImpl(), null);
    }

    @Override
    public void stop(BundleContext context) throws Exception {
        registration.unregister();
    }
}

      



Note:

  • namespace,
  • class name,
  • the name of the stop method.

For example, in the example above, they are fr.free.nrw

, ServiceActivator

and stop

, and of these three are given the full name fr.free.nrw.ServiceActivator.stop

.

Now open jstack.txt

and search for the full name. Even though the file is thousands of lines long, there will likely only be one hit, and this is a problematic flow:

at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.unregister(ServiceRegistrationImpl.java:222)
at fr.free.nrw.ServiceActivator.stop(ServiceActivator.java:30)
at org.eclipse.osgi.internal.framework.BundleContextImpl$4.run(BundleContextImpl.java:830)
at org.eclipse.osgi.internal.framework.BundleContextImpl$4.run(BundleContextImpl.java:1)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.internal.framework.BundleContextImpl.stop(BundleContextImpl.java:823)

      

In that file, go to the beginning of a paragraph that looks something like this:

"fileinstall-/home/nico/p/liferay/osgi/modules" #37 daemon prio=5 os_prio=0 tid=0x00007f39480e3000 nid=0x384f waiting on condition [0x00007f395d169000]
  java.lang.Thread.State: WAITING (parking)
    at sun.misc.Unsafe.park(Native Method)
    - parking to wait for  <0x00000000eb8defb8> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)

      

With this information, you will learn what the threading problem is and you should be able to solve it using normal Java threading debugging techniques ( 1 2 ).

+1


source


The activator you split should never block the stop method. So I doubt it can lead to the behavior you described.



0


source







All Articles