Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 330506

Summary: Re-Installing a PAR with a fragment on system.bundle hangs Virgo
Product: [RT] Virgo Reporter: Alex Blewitt <alex.blewitt>
Component: unknownAssignee: Borislav Kapukaranov <b.kapukaranov>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eclipse, glyn.normington
Version: unspecified   
Target Milestone: 3.0.0.M01   
Hardware: All   
OS: All   
Whiteboard:

Description Alex Blewitt CLA 2010-11-17 14:04:35 EST
Build Identifier: 2.1.0.RELEASE

(I've got a reproducible case for this but have not yet slimmed it down to the minimal)

I have a PAR which has a fragment on the system OSGi.bundle. (This is an EclipseLink JPA one, though with the older org.eclipse.persistence.osgi rather than Gemini JPA).

If I re-install the bundle through the admin console, it takes down all of the PAR and then goes through the re-install phase. However, if my bundle has a fragment on the system bundle, it then proceeds to try and take down everyhing (including the kernel) and ultimately hangs. A Ctrl+C produces a servicability report, but by then you're seeing messages 'org.eclipse.virgo.kernel stopped' messages which doesn't look good.

Reproducible: Didn't try

Steps to Reproduce:
I believe this is sufficient, but not yet proved it:

* Create a fragment on System.bundle
* Put it into a PAR
* Install the PAR into Virgo via the web admin
* Re-install the PAR into Virgo via the web admin
Comment 1 Glyn Normington CLA 2010-11-17 17:08:20 EST
I think it would be better to configure the fragment on the system bundle to be installed during kernel or user region initialisation rather than embedding it in a PAR which is really designed to be a self-contained entity. Perhaps you would like to try this and see if you get good results. The User Guide should provide sufficient guidance, but please come back here if not.

However, we should at least fail more gracefully in this case, so thanks for raising the bug and I'll look forward to a slimmed down test case.
Comment 2 Alex Blewitt CLA 2010-11-17 17:35:13 EST
The problem (in my specific case) is that it's a JPA sample (that isn't using Spring) and the EclipseLink support automatically creates the fragment on the system bundle. Since I'm still grappling with this to work I am not sure if it's my problem with JPA, but you're right, a workaround would be to install JPA stuff in a separate location rather than the application.
Comment 3 Alex Blewitt CLA 2010-11-17 17:37:31 EST
NB one use case for system bundle fragments I've used in the past is to expose classes available on the boot path. For example, one might have a system bundle fragment that exports the 'sun.misc' package. If someone includes that in a PAR it might be safer not to stop the system bundle but merely uninstall the fragment, though in the general case this may not be possible.
Comment 4 Glyn Normington CLA 2010-11-18 01:40:57 EST
I suspect that the refresh packages call to package admin after undeployment is where the kernel shuts down as the transitive dependencies of the undeployed bundles get refreshed, which includes stopping them and restarting them.
Comment 5 Borislav Kapukaranov CLA 2011-01-19 08:06:28 EST
Hi Alex,

Glyn was correct that the refresh packages call to package admin is the root cause - it shuts down the system bundle of the user region. It is done on uninstall of a PAR. 
Virgo's strategy for PAR re-install or refresh is a basic one - we first uninstall the old one and then install the new one. This basically means that if you have a PAR containing fragment on a system bundle, then you can do almost nothing with it - you can re-install it since it'll shut down the user region, you also can't uninstall it once you've deployed it since it'll again shut down the user region.
Basically there are two solutions:
1) somehow disable the refresh for PARs with such fragments - but that won't work so good since it'll leave the system in an incosistent state(possibly very inconsistent, depending on the PAR) until the next restart after the PAR is re-installed/uninstalled.
2) forbid having fragments on system bundles in a PAR - which me and Glyn think is the preferable solution. Note that having only fragments on system bundle will be forbidden, not having fragments at all.

I'll start implementing it. But first wanted to see what do you think?
Comment 6 Alex Blewitt CLA 2011-01-26 09:20:30 EST
I think there's two use-cases for fragments on the System bundle:

1) To add additional packages that get exported by the system bundle (e.g. via an empty Export-Package type of fragment)
2) To add code to the system bundle itself

In the latter case, I don't see how you can do that without potentially affecting other users of the system bundle, which might then cause further problems for users down the line. If I have a fragment contributed by PAR A and then I have a PAR B installed, I'll see the results of the fragment attach from A, right?

So I think disallowing fragments on the system bundle makes sense, though I could see an argument to let the former through. However, since Virgo naturally exports all of those anyway, I'm not sure it even makes sense to do 1) in the context of a Virgo runtime, since it exports everything.
Comment 7 Glyn Normington CLA 2011-01-26 10:19:14 EST
Thanks Alex. Please note that we are proposing to disallow "deploying" (using the Virgo kernel) fragments on the system bundle, but you can still attach such fragments by configuring them on the kernel startup. This makes more sense from an update point of view.
Comment 8 Borislav Kapukaranov CLA 2011-01-28 13:20:43 EST
Fix pushed. Closing the bug now.
Comment 9 Borislav Kapukaranov CLA 2011-02-28 10:07:44 EST
closing...