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
Fixed threadpool+ProcessExit problem in shutdown flow #505
Conversation
Do make test-process-exit to run
The threadpool was being shutdown too early, before the ProcessExit event was fired. This led to bugs such as NLog not shutting down (http://nlog-project.org/2011/10/30/using-nlog-with-mono.html).
No comment on the list, I'm posting my message here as well: It seems there's a small problem with the way the runtime shuts down at the moment: the thread pool (and apparently other resources) are shut down before the ProcessExit signal is fired. This is the cause for the NLog bug This pull request has a test that reproduces the problem, and a proposed patch which is probably insufficient since my first time in the runtime. The general idea is this:
Somebody who actually understands everything in there should take a look at this... For one thing, the according to the comment in mini.c, mono_domain_finalize() also seems like it should be called earlier, but going so (next to mono_runtime_shutdown) triggered a segmentation fault for me. Also, my patch duplicates code the two function calls, although other calls are already duplicated. It seems that a small cleanup/refactor could help eliminate this duplication, both across thread_manage() and System_Environment_Exit() and across mini and the interpreter (which doesn't trigger the ProcessExit event?) I'd be glad to go deeper into this if people think it's good/necessary. |
I experience the same issue. My application stops quitting properly as soon as I create a Logger instance. |
Hi Guys... Is anything happening with this PR? |
FWIW, I'm using the above mentioned fix in an NLog / ServiceStack set of services under Mono 3 (meebey packages) / Ubuntu 12.04 and we haven't run into any issues. Note however, we're still in internal staging / demo mode, and not yet heavy production use. So take my experience with a grain of salt. |
We are experiencing this problem quite pervasively, with test suites running in Windows/CLR but hanging on exit on Linux/mono. |
@sebastiang are you running into this with NLog / using the fix mentioned? In an ASP.NET (or a ServiceStack app hosted under ASPNET): protected void Application_End(object sender, EventArgs e)
{
// HACK: Works around a Mono exit issue
// http://nlog-project.org/2011/10
// https://github.com/NLog/NLog/issues/118
NLog.LogManager.Configuration = null;
} Our app is being continuously deployed, and each time we redeploy, we stop the existing service (it's an Upstart job that runs fastcgi), re-deploy and restart. |
We've been able to do this in our standalone app that runs on Linux, but we don't know of the right point at which we can do this to keep NUnit tests fixtures from failing, aside from putting it in a shutdown method on each and every one of them. (Update: Having tried a few options, there appears to be no time during the NUnit test fixture itself that setting this configuration to null helps anything. This hack seems to have to be done later in execution, but without recompiling NUnit, I'm not sure how to pull that off.) |
@kumpera, can you take a look at this? |
Any news on this front? |
Fixed threadpool+ProcessExit problem in shutdown flow
The patch could have cleaned up things a bit instead of spreading things around. It didn't handle shutdown during debugger sessions, which I'll fix locally. |
Rodrigo, I'm very excited to try this locally. Thanks for giving it a look. |
Hi rodrigo, thanks for finding the time for this. I completely agree about your comment, it seemed to me that the whole runtime shutdown process could use a refactoring, but I didn't think I was the person to be doing that :) |
Fixed threadpool+ProcessExit problem in shutdown flow Commit migrated from mono/mono@4df4b7a
Will post a description in mono-devel for discussion...