You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Oliver Heger (JIRA)" <ji...@apache.org> on 2010/02/06 18:05:27 UTC

[jira] Created: (CONFIGURATION-407) HierarchicalINIConfiguration.getSection() is not thread-safe if the global section is requested

HierarchicalINIConfiguration.getSection() is not thread-safe if the global section is requested
-----------------------------------------------------------------------------------------------

                 Key: CONFIGURATION-407
                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-407
             Project: Commons Configuration
          Issue Type: Bug
    Affects Versions: 1.6
            Reporter: Oliver Heger


If the global section of a hierarchical INI configuration is requested, a new ViewNode is created which becomes the root node of a new configuration for the global section. Nodes representing properties of the global section are added to this ViewNode. This operation temporarily changes the parent node of these nodes which may cause problems if the method is called by multiple threads concurrently. Because access to a section is a read-only operation, this should be thread-safe.

The probability that this error happens is pretty low IMO. Therefore it should be hard to create a unit test.

The issue can be fixed by synchronizing the add operation to the ViewNode.

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


[jira] Updated: (CONFIGURATION-407) HierarchicalINIConfiguration can throw an exception if the global section is accessed concurrently

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

Oliver Heger updated CONFIGURATION-407:
---------------------------------------

    Summary: HierarchicalINIConfiguration can throw an exception if the global section is accessed concurrently  (was: HierarchicalINIConfiguration.getSection() is not thread-safe if the global section is requested)

> HierarchicalINIConfiguration can throw an exception if the global section is accessed concurrently
> --------------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-407
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-407
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.6
>            Reporter: Oliver Heger
>            Assignee: Oliver Heger
>
> If the global section of a hierarchical INI configuration is requested, a new ViewNode is created which becomes the root node of a new configuration for the global section. Nodes representing properties of the global section are added to this ViewNode. This operation temporarily changes the parent node of these nodes which may cause problems if the method is called by multiple threads concurrently. Because access to a section is a read-only operation, this should be thread-safe.
> The probability that this error happens is pretty low IMO. Therefore it should be hard to create a unit test.
> The issue can be fixed by synchronizing the add operation to the ViewNode.

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


[jira] Resolved: (CONFIGURATION-407) HierarchicalINIConfiguration can throw an exception if the global section is accessed concurrently

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

Oliver Heger resolved CONFIGURATION-407.
----------------------------------------

       Resolution: Fixed
    Fix Version/s: 1.7

Fixed in subversion in revision 907793.

> HierarchicalINIConfiguration can throw an exception if the global section is accessed concurrently
> --------------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-407
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-407
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.6
>            Reporter: Oliver Heger
>            Assignee: Oliver Heger
>             Fix For: 1.7
>
>
> If the global section of a hierarchical INI configuration is requested, a new ViewNode is created which becomes the root node of a new configuration for the global section. Nodes representing properties of the global section are added to this ViewNode. This operation temporarily changes the parent node of these nodes which may cause problems if the method is called by multiple threads concurrently. Because access to a section is a read-only operation, this should be thread-safe.
> The probability that this error happens is pretty low IMO. Therefore it should be hard to create a unit test.
> The issue can be fixed by synchronizing the add operation to the ViewNode.

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


[jira] Commented: (CONFIGURATION-407) HierarchicalINIConfiguration can throw an exception if the global section is accessed concurrently

Posted by "Oliver Heger (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12831635#action_12831635 ] 

Oliver Heger commented on CONFIGURATION-407:
--------------------------------------------

With regard to concurrent access most Configuration implementations behave similar to Java collections: it is intended that they can be read concurrently by multiple threads; however, if one thread updates the configuration, the developer has to ensure proper synchronization. This is documented in the user's guide (http://commons.apache.org/configuration/userguide/overview.html#Threading_issues) and should also be stated in the Javadocs of at least the configuration base classes.

The issue this ticket is about is somewhat special because here the implementation of a logic read method did temporarily change the status of the configuration object. So synchronization was needed to make sure that this method can be called concurrently. But updates by another thread are still not supported. Therefore the tests do not update the data in the configuration.

> HierarchicalINIConfiguration can throw an exception if the global section is accessed concurrently
> --------------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-407
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-407
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.6
>            Reporter: Oliver Heger
>            Assignee: Oliver Heger
>             Fix For: 1.7
>
>
> If the global section of a hierarchical INI configuration is requested, a new ViewNode is created which becomes the root node of a new configuration for the global section. Nodes representing properties of the global section are added to this ViewNode. This operation temporarily changes the parent node of these nodes which may cause problems if the method is called by multiple threads concurrently. Because access to a section is a read-only operation, this should be thread-safe.
> The probability that this error happens is pretty low IMO. Therefore it should be hard to create a unit test.
> The issue can be fixed by synchronizing the add operation to the ViewNode.

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


[jira] Commented: (CONFIGURATION-407) HierarchicalINIConfiguration.getSection() is not thread-safe if the global section is requested

Posted by "Oliver Heger (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12831114#action_12831114 ] 

Oliver Heger commented on CONFIGURATION-407:
--------------------------------------------

Of course, you are right. The Configuration implementations are typically not thread-safe. However, it is intended that read-only access can be performed concurrently.

So I am going to change the subject of this ticket.

> HierarchicalINIConfiguration.getSection() is not thread-safe if the global section is requested
> -----------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-407
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-407
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.6
>            Reporter: Oliver Heger
>            Assignee: Oliver Heger
>
> If the global section of a hierarchical INI configuration is requested, a new ViewNode is created which becomes the root node of a new configuration for the global section. Nodes representing properties of the global section are added to this ViewNode. This operation temporarily changes the parent node of these nodes which may cause problems if the method is called by multiple threads concurrently. Because access to a section is a read-only operation, this should be thread-safe.
> The probability that this error happens is pretty low IMO. Therefore it should be hard to create a unit test.
> The issue can be fixed by synchronizing the add operation to the ViewNode.

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


[jira] Commented: (CONFIGURATION-407) HierarchicalINIConfiguration.getSection() is not thread-safe if the global section is requested

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12830775#action_12830775 ] 

Sebb commented on CONFIGURATION-407:
------------------------------------

Thread-safety means more than just synchronising changes to variables - threads that read the variable need to synch. on the same lock in order to be sure of seeing the updated value.


> HierarchicalINIConfiguration.getSection() is not thread-safe if the global section is requested
> -----------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-407
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-407
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.6
>            Reporter: Oliver Heger
>            Assignee: Oliver Heger
>
> If the global section of a hierarchical INI configuration is requested, a new ViewNode is created which becomes the root node of a new configuration for the global section. Nodes representing properties of the global section are added to this ViewNode. This operation temporarily changes the parent node of these nodes which may cause problems if the method is called by multiple threads concurrently. Because access to a section is a read-only operation, this should be thread-safe.
> The probability that this error happens is pretty low IMO. Therefore it should be hard to create a unit test.
> The issue can be fixed by synchronizing the add operation to the ViewNode.

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


[jira] Commented: (CONFIGURATION-407) HierarchicalINIConfiguration.getSection() is not thread-safe if the global section is requested

Posted by "Oliver Heger (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12830730#action_12830730 ] 

Oliver Heger commented on CONFIGURATION-407:
--------------------------------------------

Actually even an IllegalStateException can be thrown by the {{DefaultConfigurationNode}} class because the node is changed while it is assigned a parent node.

> HierarchicalINIConfiguration.getSection() is not thread-safe if the global section is requested
> -----------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-407
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-407
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.6
>            Reporter: Oliver Heger
>            Assignee: Oliver Heger
>
> If the global section of a hierarchical INI configuration is requested, a new ViewNode is created which becomes the root node of a new configuration for the global section. Nodes representing properties of the global section are added to this ViewNode. This operation temporarily changes the parent node of these nodes which may cause problems if the method is called by multiple threads concurrently. Because access to a section is a read-only operation, this should be thread-safe.
> The probability that this error happens is pretty low IMO. Therefore it should be hard to create a unit test.
> The issue can be fixed by synchronizing the add operation to the ViewNode.

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


[jira] Commented: (CONFIGURATION-407) HierarchicalINIConfiguration can throw an exception if the global section is accessed concurrently

Posted by "Oliver Heger (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12832183#action_12832183 ] 

Oliver Heger commented on CONFIGURATION-407:
--------------------------------------------

Good points. It is probably best to open a new ticket for documentation improvements related to threading issues.

I think, if there are threads that update the configuration, reader and writer threads should use the Configuration object itself as lock. Someday we might provide wrapper implementations that automatically synchronize access to configuration objects, analoguously to the functionality provided by Collections.synchronizedCollection(). But that's another story.

> HierarchicalINIConfiguration can throw an exception if the global section is accessed concurrently
> --------------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-407
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-407
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.6
>            Reporter: Oliver Heger
>            Assignee: Oliver Heger
>             Fix For: 1.7
>
>
> If the global section of a hierarchical INI configuration is requested, a new ViewNode is created which becomes the root node of a new configuration for the global section. Nodes representing properties of the global section are added to this ViewNode. This operation temporarily changes the parent node of these nodes which may cause problems if the method is called by multiple threads concurrently. Because access to a section is a read-only operation, this should be thread-safe.
> The probability that this error happens is pretty low IMO. Therefore it should be hard to create a unit test.
> The issue can be fixed by synchronizing the add operation to the ViewNode.

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


[jira] Commented: (CONFIGURATION-407) HierarchicalINIConfiguration can throw an exception if the global section is accessed concurrently

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12831176#action_12831176 ] 

Sebb commented on CONFIGURATION-407:
------------------------------------

If the same INIConfiguration instance is shared between threads, and one updates the shared config, then in the absence of synchronization, the other threads won't necessarily see the updated values. This is because the JVM is allowed to cache values in both the writer and reader threads.

In order to ensure that cached values are correctly published, some form on synch. is needed. 
For example, the reader has to synch. on the same object as the writer.
Or one can use volatile.

Or, for example the configuration can be created in one thread, which then starts other threads that read it. Thread.start() acts as the lock in this case.
But if the writer thread subsequently changes the shared state, additional synch. will be needed to guarantee safe publication to the existing threads.

By the way, the test case does not appear to test changes to the global INIConfiguration.

> HierarchicalINIConfiguration can throw an exception if the global section is accessed concurrently
> --------------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-407
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-407
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.6
>            Reporter: Oliver Heger
>            Assignee: Oliver Heger
>             Fix For: 1.7
>
>
> If the global section of a hierarchical INI configuration is requested, a new ViewNode is created which becomes the root node of a new configuration for the global section. Nodes representing properties of the global section are added to this ViewNode. This operation temporarily changes the parent node of these nodes which may cause problems if the method is called by multiple threads concurrently. Because access to a section is a read-only operation, this should be thread-safe.
> The probability that this error happens is pretty low IMO. Therefore it should be hard to create a unit test.
> The issue can be fixed by synchronizing the add operation to the ViewNode.

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


[jira] Commented: (CONFIGURATION-407) HierarchicalINIConfiguration can throw an exception if the global section is accessed concurrently

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12831679#action_12831679 ] 

Sebb commented on CONFIGURATION-407:
------------------------------------

I think the user guide needs to be a lot clearer about what manual synch. is required. What should the reader threads synchronize on?

Thread-safety and correct publication is only guaranteed if the writer and reader threads use the *same* lock, so the reader thread needs to know what lock to use.


> HierarchicalINIConfiguration can throw an exception if the global section is accessed concurrently
> --------------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-407
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-407
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.6
>            Reporter: Oliver Heger
>            Assignee: Oliver Heger
>             Fix For: 1.7
>
>
> If the global section of a hierarchical INI configuration is requested, a new ViewNode is created which becomes the root node of a new configuration for the global section. Nodes representing properties of the global section are added to this ViewNode. This operation temporarily changes the parent node of these nodes which may cause problems if the method is called by multiple threads concurrently. Because access to a section is a read-only operation, this should be thread-safe.
> The probability that this error happens is pretty low IMO. Therefore it should be hard to create a unit test.
> The issue can be fixed by synchronizing the add operation to the ViewNode.

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