Hi Sebastian,

this is spot on. If you're not subscribed to the mailing list yet, it's a
good time to do so now.

At first sight I would argue that in a typical deployment, database tables
are created by the system administrator during setup. I cannot recommend to
create them later on the fly. If a system administrator is a bit of
nitpicky kind he will most likely even revoke the privileges of an
application to create or drop tables. When 64 threads try to create the
same table at the same time as you describe it here I would expect 63
threads to fail with an exception. I do not know how the adonetappender
reacts to such a situation. If it fails with an exception, the logging
system should fail stop and output an error log to the internal logging.

Please note that from an architecture point of view you may want to buffer
events before flushing them to the database and you will further want to
filter events such that the throughput stays well below 500 to 1000 events
per second. These numbers obviously depend on the infrastructure of your
database server and application etc but I would not require the database to
chew more than that when it should do also other things beyond persisting
log events.

Best regards,
Dominik

Am Do., 12. Juli 2018 um 18:14 Uhr schrieb Morgenbesser, Sebastian <
sebastian.morgenbes...@rubicon.eu>:

> Hi,
>
>
>
> I am Sebastian and working for a Software company in Vienna.
>
> I recently noticed a strange issue with log4net and the AdoNetAppender and
> it would be nice if anyone could comment on this.
>
>
>
> Its quite an Edge Case I know but the implication is that the Application
> will freeze and no Exception is thrown which is kind of scary.
>
> I have made a small example C# project to illustrate the issue which I can
> provide, but first I want to explain the issue.
>
>
>
> The scenario is like this:
>
> ·         Visual Studio C# Console Application. Log4net (latest version)
> embedded as dll, MS SQL Server 2016 (but I guess this doesn’t matter), .NET
> Framework > 4.5
>
> ·         The Application starts and the Logger is initialized
> (containing a AdoNetAppender pointing to an existing Database on MS SQL
> Server – localhost)
>
> o   The code is something like this:
>
> o
>
> ·         After that happened, the Application is going to DROP the
> Database containing the Table that log4net will log to and recreates the
> database with all tables
>
> o   This happens because every time the console starts the Log-Database
> should be empty  (I know there are other ways like truncate oder Drop Table
> but lets stay with me to understand the problem)
>
> ·         So at this point the Database containing the Log Table has been
> recreated.
>
> ·         Now the Application starts a number Threads (in my example 64,
> but I guess it works with less) and waits for them to finish
>
> ·         In the Do() Method of the Thread, the thread simply tries to
> log an Error Message to the previously initialized logger
>
> ·         The Result is that the Application freezes and will never
> return (0% CPU). Also no log messages arrive in the database.
>
> ·         I am guessing there is some kind of deadlock situation inside
> log4net if multiple threads try to “initialize” the database connection to
> the recreated database again but in detail I have no idea what happens.
>
> ·         No exception is thrown, the threads just never finish there
> Do() Method
>
>
>
> So if I skip the part where I Recreate the database (with DROP und CREATE
> Database), then it works.
>
> Also if put a log statement after the recreation of the database but
> BEFORE the multithreaded part starts, it also works.
>
>
>
> Please advise what to do, is this the right place to address such an issue
> or should it be posted as an issue on jira?
>
>
>
> Greets
>
> Sebastian Morgenbesser
>
>
>
>
>


-- 
Dominik Psenner

Reply via email to