Menu

#8 AbstractCachingLoggerFactoryAdapter is not thread-safe

v2.0
open-rejected
logging (14)
5
2009-12-14
2009-12-03
Anonymous
No

There is a bug in the GetLoggingInternal method of the AbstractCachingLoggerFactoryAdapter making it vurnerable to race condition. The developer of that method assumed that reading from a Hashtable is always thread-safe, while it's only thread-safe when no elements can be added at the same time. In this case reads (calls to _cachedLoggers[name]) can be mixed with a write operation (call to _cachedLoggers.Add(name, log)), because the read is not enclosed in the lock statement.

There are two solutions two this problem:
1. enclose the read operation inside of the lock operation (but this isn't good for performance)
2. Make _cachedLoggers instances readonly and replace them completely by a new instance when adding. The attached file shows a possible implementation of this solution.

Discussion

  • Nobody/Anonymous

    Fix for AbstractCachingLoggerFactoryAdapter.GetLoggerInternal method.

     
  • Steven

    Steven - 2009-12-03

    My apologies for posting this bug report without a Source Forge account. As you can see I now created an account.

     
  • Erich Eichinger

    Erich Eichinger - 2009-12-14

    there is a lock, don't worry

     
  • Erich Eichinger

    Erich Eichinger - 2009-12-14
    • status: open --> closed-rejected
     
  • Erich Eichinger

    Erich Eichinger - 2009-12-14
    • status: closed-rejected --> open-rejected
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.