Uploaded image for project: 'Commons Configuration'
  1. Commons Configuration
  2. CONFIGURATION-390

AbstractHierarchicalFileConfiguration is not thread safe

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.6
    • Fix Version/s: None
    • Component/s: File reloading
    • Labels:
      None

      Description

      AbstractHierarchicalFileConfiguration doesn't implement the same locking mechanism found in AbstractFileConfiguration. The consequence is that getting a property while the configuration is being reloaded by another thread can return an invalid result.

      This can be demonstrated by changing testDeadlockWithReload() in TestCombinedConfiguration to use an XMLConfiguration instead of a PropertiesConfiguration.

      Here is a reduced test case:

      public void testConcurrentGetAndReload() throws Exception
      {
          //final FileConfiguration config = new PropertiesConfiguration("test.properties");
          final FileConfiguration config = new XMLConfiguration("test.xml");
          config.setReloadingStrategy(new FileAlwaysReloadingStrategy());
      
          assertTrue("Property not found", config.getProperty("test.short") != null);
      
          new Thread()
          {
              public void run()
              {
                  for (int i = 0; i < 1000; i++)
                  {
                      config.reload();
                  }
              }
          }.start();
          
          for (int i = 0; i < 1000; i++)
          {
              assertTrue("Property not found", config.getProperty("test.short") != null); // failure here
          }
      }
      

      The test doesn't always fail. It does about 50% of the time.

        Attachments

        1. TestSuite.txt
          231 kB
          Stephen Kinser
        2. configtest.tar.gz
          2 kB
          Stephen Kinser
        3. commons-configuration-390.patch
          5 kB
          Oliver Heger

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                ebourg Emmanuel Bourg
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated: