Log4net
  1. Log4net
  2. LOG4NET-167

ArrayOutOfBounds Exception in MemoryAppender.getEvents()

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.10
    • Fix Version/s: 1.2.11
    • Component/s: Appenders
    • Labels:
      None
    • Environment:
      Windows Vista and XP.

      Description

      Getting this every once in a while.
      No specific reproduction scenario.

      Destination array was not long enough. Check destIndex and length, and the array's lower bounds.
      at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
      at System.Collections.ArrayList.ToArray(Type type)
      at log4net.Appender.MemoryAppender.GetEvents()

        Activity

        Hide
        Ron Grabowski added a comment -

        It looks like elements can be added to the array while the Array.CopyTo is taking place which means the size/count could become out of bounds. This should fix it:

        lock (m_eventsList.SyncRoot)

        { return (LoggingEvent[])m_eventsList.ToArray(typeof(LoggingEvent)); }
        Show
        Ron Grabowski added a comment - It looks like elements can be added to the array while the Array.CopyTo is taking place which means the size/count could become out of bounds. This should fix it: lock (m_eventsList.SyncRoot) { return (LoggingEvent[])m_eventsList.ToArray(typeof(LoggingEvent)); }
        Hide
        Ron Grabowski added a comment -

        How are you using the MemoryAppender Kenny? Is it from a single thread?

        Show
        Ron Grabowski added a comment - How are you using the MemoryAppender Kenny? Is it from a single thread?
        Hide
        Kenny Clement added a comment -

        No, we're using several background workers at the same time.
        The lock makes perfect sense.

        Show
        Kenny Clement added a comment - No, we're using several background workers at the same time. The lock makes perfect sense.
        Hide
        Steve Glendinning added a comment -

        I saw multiple issues of thread safety when using MemoryAppender in a multi-threaded unit test suite. Symptoms were as previously reported, and also included spurious NullReferenceExceptions.

        The attached patch fully fixes the issue for me, please consider for inclusion in the next bugfix release.

        Steve Glendinning

        Show
        Steve Glendinning added a comment - I saw multiple issues of thread safety when using MemoryAppender in a multi-threaded unit test suite. Symptoms were as previously reported, and also included spurious NullReferenceExceptions. The attached patch fully fixes the issue for me, please consider for inclusion in the next bugfix release. Steve Glendinning
        Hide
        Stefan Bodewig added a comment -

        Steve's patch is in as svn revision 1166569.

        Note that subclasses can still break thread-safety since m_eventsList is protected (and not even readonly).

        Show
        Stefan Bodewig added a comment - Steve's patch is in as svn revision 1166569. Note that subclasses can still break thread-safety since m_eventsList is protected (and not even readonly).

          People

          • Assignee:
            Ron Grabowski
            Reporter:
            Kenny Clement
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development