-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
g3log - Process hangs "because" of the LogWorker destructor #520
Comments
At g3log exit, it flushes all sinks (default, homemade or through g3sinks) until all messages are taken care of.
Assuming the system has used g3log for a substantial amount of time - it's "unusual" that something like this would surface now unless other things in the system setup changed. Just my thoughts about it. |
This issue happens during a normal exit. When a crash occurs in the DLL it will crash the whole application as well. I call a native destroy method which shuts down everything inside the native library including the logger. It will not log anything else after I destroyed it. I want to also note that I have a version which is an executable by itself instead of a native library for tests. So it handles basically all the calls I was doing in my .NET app in C++, here I don't really have issues, when the code reaches the end, it properly exits. |
Essentially, a better solution would be to completely free the library out of my process' memory. This was my initial attempt to fix the issue but even if I use the |
And this version is what was running successfully with g3log, I gather? And now there's an attempt to change the setup and using dlls which is now experiencing issues? ** If you search for closed issues and DLL you can find some common issues with DLLs and Windows when working with g3log Issue #486 incompatible versions debug release One thing I’ve seen before is using DLLs in a way that breaks windows standard. Initialization should happpen in the main executable and not in the DLL Another issue I’ve seen is when a static instantiations that are internal to g3log is attempted to be shared shared across DLL. DLL static initialization and destruction are a mess in Windows and most devs struggle to get this right Other issues I’ve seen
|
In fact, I also have an Android version of the native code, compiled as a shared object and made to be ran by an android application and once again, I don't have any issues here either. This case isn't much different I'm reproducing what the android platform does by creating a DLL interface and using C# for actually running the native methods. So can't really instantiate the logger within the managed code. It might just as well be a platform issue by the fact that I use a DLL instead of an executable though I really feel like this shouldn't happen since a DLL isn't much different from an executable though I might be wrong on this. |
If I understand you correctly you are instantiating g3log inside the DLL. How and when and where are you instantiating the logger object? |
And init Is called after the DLL is fully loaded, or during the load/initialization of the DLL?By understanding the whole load sequence it would be easier to see if that’s what’s going sideways Sent from my iPhoneOn May 14, 2024, at 06:19, RoyalcraftDev ***@***.***> wrote:
Initializing the logger is almost the first thing I do.
image.png (view on web)
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: ***@***.***>
|
I think I understand what's going on. g3log relies on proper RAII initialization for destruction. Here the logger instance is hidden as a static object within a function, so at process exit the destructor is never called, and therefore the logging sinks aren't flushed. How static instances are destroyed is AFAIK defined per each specific system. Some windows specific work around that specifically touched this are mentioned in |
Seems like the root cause for this was that initialization and destruction of the logger was not conforming to expected usage. https://kjellkod.github.io/g3log/g3log_usage.html#adding-and-removing-sinks Windows dll work arounds as handled in #88 (comment) and #91 were given. |
Context
I was trying to fix an issue where my process would stay on even after executing. In short, my app uses methods from a native library I created and obviously uses
g3log
. Though, I didn't have in mind at all it would be the cause. For long hours, I was trying different things to get rid of the issue, but nothing really worked. I ended up usingProcess Hacker
to find more information about that zombie process. In the process details, it showed one thread left. I naturally checked the stack and saw things related to await
state. Then after reading further, I saw lines related tog3log
, more precisely these lines were related to the destructor of theLogWorker
.Thread State: Wait:WrAlertByThreadId
Afterwards, I checked in the source code of
g3log
and looked at the destructor of it and found these lines:(My) Solution
I didn't really think too much about it, I just commented the lines, and after recompiling the library, the process was correctly exiting!
But...
I doubt that commenting lines of code like that is very nice, it feels more like a hack than anything else. I'd like to know if there is maybe something that I did wrong that resulted in this behavior or just a bug inside the library.
Additional Context
Platform: Windows 10
Language Version: C++14
Compiler: MSVC
Note: The codebase of the native library is quite old, around 2011 and so does the version of
g3log
used. After checking I saw files from 2011-2015 ofg3log
The text was updated successfully, but these errors were encountered: