QuickLogger icon indicating copy to clipboard operation
QuickLogger copied to clipboard

Using logging in COM dll hangs when application is closed

Open JWBokx opened this issue 4 years ago • 11 comments

Hello all,

I'm new here and landed here searching a solution for my problem. I use the quick library and logger already in standard VCL programs with no problems at all.

Now my colleague and I are building a plugin for Outlook and Word. For this we are using the components of add-in express. So we're building a COM plugin for local instance of office. The problem is when closing Word, It hangs. In outlook this isn't a problem, so just word.

Debugging it I found the point it stops responding. In Quick,Logger.pas at line 1315:

  fThreadProviderLog.Terminate;
  fThreadProviderLog.WaitFor;
  fThreadProviderLog.Free;
  //if Assigned(fProviders) then fProviders.Free;
  FreeAndNil( fProviders );
  fCustomTags := nil;
  FreeAndNil( fLogQueue ); 

The .WaitFor is never returning... I also had a breakpoint in the thread that has to stop, the while loop is ended correctly. So it seems the thread is terminatied after the calling of .Terminate method.

Kind regards,

Jan

JWBokx avatar Nov 22 '21 13:11 JWBokx

Hi, have you found any workaround?

casagrandeenrico avatar Feb 09 '22 09:02 casagrandeenrico

I have kind of workaround, but I don't like it. I have remarked the line around 1320 fThreadProviderLog.WaitFor; in Quick.Logger. Maybe the line number is not correct in your source because of the changes in my source. Also changed most of the .free calls to FreeAndNil() Some of these had a if assigned(x) but only a free. If the code is somehow executed twice or more the if assigned wil return true, while this is not the case.

The deadlock is fixed with this, only an exception in during debugging I can not fix. Debugging the shutdown code in Word or Excel is quit dramatically. If a breakpoint is set, the execption is raised somewhere else. Without the debugger the exception seems not to occur, or it is and it's not visible.

So it's a workaround, but not one that feels good. I'm running out of time to continue debugging, so I have to leave it this way for now.

JWBokx avatar Feb 09 '22 10:02 JWBokx

Could you try to replace this line with: if not IsLibrary then fThreadProviderLog.WaitFor;

exilon avatar Feb 10 '22 22:02 exilon

Oh good one. I will try it on Monday, I have a day off now.

JWBokx avatar Feb 11 '22 13:02 JWBokx

I have the FreeAndNil( fThreadProviderLog) also in the if included. It results in a few memory leaks report, but Word/Excel is closing fine now without an acc.violation. The shutdown proces of Word/Excel is difficult to debug. With the if, it also works in normal programs and can use the same source.

I do think changing the .Free calls to a FreeAndNil call can solve some strange behavings. But that's up to you. It seems the logger is not in use within a COM dll for Office... So I'm the only one with this strange behaviour.

JWBokx avatar Feb 16 '22 10:02 JWBokx

Without these FreeAndNil changes, does Word/Excel hang when closing? Can you send me a minimum sample so I can reproduce it?

exilon avatar Feb 16 '22 20:02 exilon

A minimal example is not possible. We use a closed source component as base for the com dll. This is to prevent we had all the com registration code for office to figure out. But this component is not free, an there is no trial version, only a 30 day money back. So for testing no t fun

JWBokx avatar Feb 18 '22 15:02 JWBokx

Oh good one. I will try it on Monday, I have a day off now.

Did you try this?

exilon avatar Jun 14 '22 19:06 exilon

Yes I did, sorry forgot to mention... It does help within Outlook, but not within Word.... Excel not tested yet. At the moment no plugin is needed for excel. Very strange, and the only way is now not to use the logging in Word.

All I can see the closing down of Outlook is different from Word. So in Outlook the finalization en destructors are called and can be debugged. But Word just kils the plugin and comes in a kind of deadlock in one of the destructors. The debugger is hanging too and no way to break the execution....

JWBokx avatar Jun 16 '22 07:06 JWBokx

Does anyone have an example on how to use the QuickLogger.dll using GreyLog as provider?

otomazeli avatar Jun 01 '23 20:06 otomazeli

I also encountered this issue, how do I solve it?

Evanchl avatar Nov 25 '23 06:11 Evanchl