Uploaded image for project: 'Log4net'
  1. Log4net
  2. LOG4NET-462

ReadOnlyPropertiesDictionary not thread safe

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 1.2.13
    • Fix Version/s: 1.2.15, 1.3.0
    • Component/s: None
    • Labels:

      Description

      I have an application that runs as a windows service and spins up multiple AppDomains, each with their own loggers. I will often run into an issue where log4net appears to be causing one or more of the spun up AppDomains to not function properly. The relevant stack trace looks as follows:

      System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
      at System.Collections.Hashtable.HashtableEnumerator.MoveNext()
      at log4net.Util.ReadOnlyPropertiesDictionary.GetObjectData(Serialization info, StreamingContext context)
      at System.Runtime.Serialization.ObjectCloneHelper.GetObjectData(Object serObj, String& typeName, String& assemName, String[]& fieldNames, Object[]& fieldValues)

      I have not been able to find the specific conditions to reproduce this but it happens often enough to be a huge problem. Looking at the log4net source, the ReadOnlyPropertiesDictionary.GetObjectData() method does a foreach over the InnerHashTable collection but there is nothing to stop that collection from being modified outside of that loop which is leading to the exception. I am not sure where in my code I would be doing anything that modified that collection indirectly but I do know that I push several things on and off of the LogicalThreadContext.

        Activity

        Hide
        bodewig Stefan Bodewig added a comment -

        Well, the inheritance hierarchy is pretty strange, PropertiesDictionary is a subclass of ReadOnlyPropertiesDictionary - and happily modifies the internal hashtable. To be honest I don't understand why it looks the way it does, in particualr since PropertiesDictionary reimplements most of the methods anyway.

        I think the problem should be fixed with svn revision 1675705 but for 1.3 we may as well rethink the inheritance hierarchy anyway.

        Show
        bodewig Stefan Bodewig added a comment - Well, the inheritance hierarchy is pretty strange, PropertiesDictionary is a subclass of ReadOnlyPropertiesDictionary - and happily modifies the internal hashtable. To be honest I don't understand why it looks the way it does, in particualr since PropertiesDictionary reimplements most of the methods anyway. I think the problem should be fixed with svn revision 1675705 but for 1.3 we may as well rethink the inheritance hierarchy anyway.
        Hide
        bodewig Stefan Bodewig added a comment -

        merged to 1.2.x with svn revision 1714267

        Show
        bodewig Stefan Bodewig added a comment - merged to 1.2.x with svn revision 1714267

          People

          • Assignee:
            Unassigned
            Reporter:
            ttutko Tom Tutko
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development