You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Karl Pauls (JIRA)" <ji...@apache.org> on 2007/08/09 18:47:42 UTC

[jira] Created: (FELIX-335) Configuration Admin updates with empty properties and throws NullPointerExceptions due to race condition

Configuration Admin updates with empty properties and throws NullPointerExceptions due to race condition
--------------------------------------------------------------------------------------------------------

                 Key: FELIX-335
                 URL: https://issues.apache.org/jira/browse/FELIX-335
             Project: Felix
          Issue Type: Bug
          Components: Configuration Admin
            Reporter: Karl Pauls
         Attachments: empty-properties.patch

There appears to be a race condition in the configuration admin that allows managed services to get updated with empty properties (but not null). Furthermore, due to the same bug NullPointerExceptions appear under heavy load. 

Fortunately, I think I was able to isolate the bug. The issue is that configurations are persisted when created but before they are initialized (i.e., given a configuration). If during this window a new ManagedService appears it gets updated with an empty Dictionary. Likewise, if the configuration is re-read after such an update attempt it does not have a pid which causes the null pointer exceptions.

The fix seems to be rather simple  (unless I'm missing something :-) but took me some time to figure out. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (FELIX-335) Configuration Admin updates with empty properties and throws NullPointerExceptions due to race condition

Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-335?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Felix Meschberger resolved FELIX-335.
-------------------------------------

       Resolution: Fixed
    Fix Version/s: 1.0.0

Committed the fixes to Rev. 567688 and deployed a new snapshot of this bundle.

> Configuration Admin updates with empty properties and throws NullPointerExceptions due to race condition
> --------------------------------------------------------------------------------------------------------
>
>                 Key: FELIX-335
>                 URL: https://issues.apache.org/jira/browse/FELIX-335
>             Project: Felix
>          Issue Type: Bug
>          Components: Configuration Admin
>            Reporter: Karl Pauls
>            Assignee: Felix Meschberger
>             Fix For: 1.0.0
>
>         Attachments: ConfigAdmin.FELIX-335.patch, ConfigAdmin.FELIX-335_2.patch, empty-properties.patch
>
>
> There appears to be a race condition in the configuration admin that allows managed services to get updated with empty properties (but not null). Furthermore, due to the same bug NullPointerExceptions appear under heavy load. 
> Fortunately, I think I was able to isolate the bug. The issue is that configurations are persisted when created but before they are initialized (i.e., given a configuration). If during this window a new ManagedService appears it gets updated with an empty Dictionary. Likewise, if the configuration is re-read after such an update attempt it does not have a pid which causes the null pointer exceptions.
> The fix seems to be rather simple  (unless I'm missing something :-) but took me some time to figure out. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (FELIX-335) Configuration Admin updates with empty properties and throws NullPointerExceptions due to race condition

Posted by "Karl Pauls (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-335?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Karl Pauls closed FELIX-335.
----------------------------


I asked Ronald Spierenburg to run it through our (even more) involved tests and he wasn't able to produce any problems -- hence, I'm going to close this issue. Thanks a lot for fixing these issues so quickly!

> Configuration Admin updates with empty properties and throws NullPointerExceptions due to race condition
> --------------------------------------------------------------------------------------------------------
>
>                 Key: FELIX-335
>                 URL: https://issues.apache.org/jira/browse/FELIX-335
>             Project: Felix
>          Issue Type: Bug
>          Components: Configuration Admin
>            Reporter: Karl Pauls
>            Assignee: Felix Meschberger
>             Fix For: 1.0.0
>
>         Attachments: ConfigAdmin.FELIX-335.patch, ConfigAdmin.FELIX-335_2.patch, empty-properties.patch
>
>
> There appears to be a race condition in the configuration admin that allows managed services to get updated with empty properties (but not null). Furthermore, due to the same bug NullPointerExceptions appear under heavy load. 
> Fortunately, I think I was able to isolate the bug. The issue is that configurations are persisted when created but before they are initialized (i.e., given a configuration). If during this window a new ManagedService appears it gets updated with an empty Dictionary. Likewise, if the configuration is re-read after such an update attempt it does not have a pid which causes the null pointer exceptions.
> The fix seems to be rather simple  (unless I'm missing something :-) but took me some time to figure out. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (FELIX-335) Configuration Admin updates with empty properties and throws NullPointerExceptions due to race condition

Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-335?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12521075 ] 

Felix Meschberger commented on FELIX-335:
-----------------------------------------

I created now my own test cases, which could reproduce the initially reported issues as well as those reported by Karl on 16/Aug. Both issues have been resolved and the service seems to work correctly.

I will commit these fixes now and deploy a new snapshot, such that regular users may also test.

> Configuration Admin updates with empty properties and throws NullPointerExceptions due to race condition
> --------------------------------------------------------------------------------------------------------
>
>                 Key: FELIX-335
>                 URL: https://issues.apache.org/jira/browse/FELIX-335
>             Project: Felix
>          Issue Type: Bug
>          Components: Configuration Admin
>            Reporter: Karl Pauls
>            Assignee: Felix Meschberger
>         Attachments: ConfigAdmin.FELIX-335.patch, ConfigAdmin.FELIX-335_2.patch, empty-properties.patch
>
>
> There appears to be a race condition in the configuration admin that allows managed services to get updated with empty properties (but not null). Furthermore, due to the same bug NullPointerExceptions appear under heavy load. 
> Fortunately, I think I was able to isolate the bug. The issue is that configurations are persisted when created but before they are initialized (i.e., given a configuration). If during this window a new ManagedService appears it gets updated with an empty Dictionary. Likewise, if the configuration is re-read after such an update attempt it does not have a pid which causes the null pointer exceptions.
> The fix seems to be rather simple  (unless I'm missing something :-) but took me some time to figure out. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (FELIX-335) Configuration Admin updates with empty properties and throws NullPointerExceptions due to race condition

Posted by "Karl Pauls (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-335?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12520362 ] 

Karl Pauls commented on FELIX-335:
----------------------------------

With your patch, I see the following exception appear quite often in a heavily multithreaded project:

java.lang.NullPointerException
        at org.apache.felix.cm.file.FilePersistenceManager.encodePid(FilePersistenceManager.java:140)
        at org.apache.felix.cm.file.FilePersistenceManager.getFile(FilePersistenceManager.java:473)
        at org.apache.felix.cm.file.FilePersistenceManager.store(FilePersistenceManager.java:394)
        at org.apache.felix.cm.impl.ConfigurationImpl.store(ConfigurationImpl.java:340)
        at org.apache.felix.cm.impl.ConfigurationImpl.setBundleLocation(ConfigurationImpl.java:223)
        at org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.run(ConfigurationManager.java:840)
        at org.apache.felix.cm.impl.UpdateThread.run(UpdateThread.java:89) 

> Configuration Admin updates with empty properties and throws NullPointerExceptions due to race condition
> --------------------------------------------------------------------------------------------------------
>
>                 Key: FELIX-335
>                 URL: https://issues.apache.org/jira/browse/FELIX-335
>             Project: Felix
>          Issue Type: Bug
>          Components: Configuration Admin
>            Reporter: Karl Pauls
>            Assignee: Felix Meschberger
>         Attachments: ConfigAdmin.FELIX-335.patch, empty-properties.patch
>
>
> There appears to be a race condition in the configuration admin that allows managed services to get updated with empty properties (but not null). Furthermore, due to the same bug NullPointerExceptions appear under heavy load. 
> Fortunately, I think I was able to isolate the bug. The issue is that configurations are persisted when created but before they are initialized (i.e., given a configuration). If during this window a new ManagedService appears it gets updated with an empty Dictionary. Likewise, if the configuration is re-read after such an update attempt it does not have a pid which causes the null pointer exceptions.
> The fix seems to be rather simple  (unless I'm missing something :-) but took me some time to figure out. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (FELIX-335) Configuration Admin updates with empty properties and throws NullPointerExceptions due to race condition

Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-335?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Felix Meschberger updated FELIX-335:
------------------------------------

    Attachment: ConfigAdmin.FELIX-335_2.patch

Thanks for the feedback.

I went over the code again and again found some issues:

(1) It seems that when a ManagedService is registered and a new configuration is found, the configuration is immediately bound to the ManagedService. I assume, this is probably wrong. So I added precaution to not bind brand new configuration to the ManagedService.

(2) The FilePersistenceManager does not seem to act very well in multithreaded situations: A configuration file is directly written and thus may be read at the same time and hence returning nothing at. I added synchronization to the load and store methods to prevent same-time access to files as well as have the store method write to a temporary file which is renamed when done.

Attached, find a new patch, which is complete in a sense, that it includes the changes of yesterday.

Sorry to misuse you as the testbed for this... But I cannot currently come up with a good muli-threaded test case.

> Configuration Admin updates with empty properties and throws NullPointerExceptions due to race condition
> --------------------------------------------------------------------------------------------------------
>
>                 Key: FELIX-335
>                 URL: https://issues.apache.org/jira/browse/FELIX-335
>             Project: Felix
>          Issue Type: Bug
>          Components: Configuration Admin
>            Reporter: Karl Pauls
>            Assignee: Felix Meschberger
>         Attachments: ConfigAdmin.FELIX-335.patch, ConfigAdmin.FELIX-335_2.patch, empty-properties.patch
>
>
> There appears to be a race condition in the configuration admin that allows managed services to get updated with empty properties (but not null). Furthermore, due to the same bug NullPointerExceptions appear under heavy load. 
> Fortunately, I think I was able to isolate the bug. The issue is that configurations are persisted when created but before they are initialized (i.e., given a configuration). If during this window a new ManagedService appears it gets updated with an empty Dictionary. Likewise, if the configuration is re-read after such an update attempt it does not have a pid which causes the null pointer exceptions.
> The fix seems to be rather simple  (unless I'm missing something :-) but took me some time to figure out. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (FELIX-335) Configuration Admin updates with empty properties and throws NullPointerExceptions due to race condition

Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-335?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Felix Meschberger reassigned FELIX-335:
---------------------------------------

    Assignee: Felix Meschberger

> Configuration Admin updates with empty properties and throws NullPointerExceptions due to race condition
> --------------------------------------------------------------------------------------------------------
>
>                 Key: FELIX-335
>                 URL: https://issues.apache.org/jira/browse/FELIX-335
>             Project: Felix
>          Issue Type: Bug
>          Components: Configuration Admin
>            Reporter: Karl Pauls
>            Assignee: Felix Meschberger
>         Attachments: empty-properties.patch
>
>
> There appears to be a race condition in the configuration admin that allows managed services to get updated with empty properties (but not null). Furthermore, due to the same bug NullPointerExceptions appear under heavy load. 
> Fortunately, I think I was able to isolate the bug. The issue is that configurations are persisted when created but before they are initialized (i.e., given a configuration). If during this window a new ManagedService appears it gets updated with an empty Dictionary. Likewise, if the configuration is re-read after such an update attempt it does not have a pid which causes the null pointer exceptions.
> The fix seems to be rather simple  (unless I'm missing something :-) but took me some time to figure out. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (FELIX-335) Configuration Admin updates with empty properties and throws NullPointerExceptions due to race condition

Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-335?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Felix Meschberger updated FELIX-335:
------------------------------------

    Attachment: ConfigAdmin.FELIX-335.patch

Thanks for reporting this issue.

After looking deeper into the problems, I realize there is more than just this:

(1) If a configuration object is created it has to be persisted (104.7.1) but getProperties() must return null as long as the configuration object is not updated with properties. If now, the framework (or actually the Configuration Admin service) is restarted before such an update takes place, I assume, getProperties() must still return null after the restart. Currently, empty properties is returned in this case.

(2) As a configuration object has to be persisted upon creation, the save operation is where I originally put it. But it is correct, that there is a race condition, where multiple configuration objects might be created or the may be incomplete.

(3) If a ManagedService is registered but no configuration is available (assuming that newly created configuration prior to a first update is equivalent to non-existing) the updated() method must be called with null. Currently, either a NullPointerException may occurr or an empty directory may wrongly be given to the updated() method.

(4) If a ManagedService is updated with configuration, the bundle location is not always set on the configuration object.

(5) it may be, that the callPlugins method is called with a configuration object, which is new and therefore getProperties() returns null and hence the callPlugins might throw a NullPointerException.

Given all these issues, I restructured accessing configurations from the cache and the persistent store as well as ensuring the "new" state survives a restart.

What do you think ?

> Configuration Admin updates with empty properties and throws NullPointerExceptions due to race condition
> --------------------------------------------------------------------------------------------------------
>
>                 Key: FELIX-335
>                 URL: https://issues.apache.org/jira/browse/FELIX-335
>             Project: Felix
>          Issue Type: Bug
>          Components: Configuration Admin
>            Reporter: Karl Pauls
>            Assignee: Felix Meschberger
>         Attachments: ConfigAdmin.FELIX-335.patch, empty-properties.patch
>
>
> There appears to be a race condition in the configuration admin that allows managed services to get updated with empty properties (but not null). Furthermore, due to the same bug NullPointerExceptions appear under heavy load. 
> Fortunately, I think I was able to isolate the bug. The issue is that configurations are persisted when created but before they are initialized (i.e., given a configuration). If during this window a new ManagedService appears it gets updated with an empty Dictionary. Likewise, if the configuration is re-read after such an update attempt it does not have a pid which causes the null pointer exceptions.
> The fix seems to be rather simple  (unless I'm missing something :-) but took me some time to figure out. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (FELIX-335) Configuration Admin updates with empty properties and throws NullPointerExceptions due to race condition

Posted by "Karl Pauls (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-335?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Karl Pauls updated FELIX-335:
-----------------------------

    Attachment: empty-properties.patch

> Configuration Admin updates with empty properties and throws NullPointerExceptions due to race condition
> --------------------------------------------------------------------------------------------------------
>
>                 Key: FELIX-335
>                 URL: https://issues.apache.org/jira/browse/FELIX-335
>             Project: Felix
>          Issue Type: Bug
>          Components: Configuration Admin
>            Reporter: Karl Pauls
>         Attachments: empty-properties.patch
>
>
> There appears to be a race condition in the configuration admin that allows managed services to get updated with empty properties (but not null). Furthermore, due to the same bug NullPointerExceptions appear under heavy load. 
> Fortunately, I think I was able to isolate the bug. The issue is that configurations are persisted when created but before they are initialized (i.e., given a configuration). If during this window a new ManagedService appears it gets updated with an empty Dictionary. Likewise, if the configuration is re-read after such an update attempt it does not have a pid which causes the null pointer exceptions.
> The fix seems to be rather simple  (unless I'm missing something :-) but took me some time to figure out. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.