Azure / azure-functions-host

The host/runtime that powers Azure Functions
https://functions.azure.com
MIT License
1.92k stars 441 forks source link

Background threads not being stopped during shutdown #2729

Open brettsam opened 6 years ago

brettsam commented 6 years ago

It appears there are cases where calling HostingEnvironment.InitiateShutdown() will not stop all background threads. This means that if someone is in this situation and has exceeded the thread count threshold, they will infinitely repeat starting/stopping the host (due to the Health Monitor shutting it down). Only restarting the site manually will fix it.

Found this which has some examples: https://stackoverflow.com/questions/4432141/how-to-properly-unload-an-appdomain-using-c/5863164

I'm waiting on a concrete sample from this customer. When we have it, I'll do some more investigation into whether this is something we can help with.

paulbatum commented 6 years ago

It might be completed unrelated, but I noticed that post talked about how an app domain might fail to unload if stuck in a finalizer, and this issue reported recently has a edge.js finalizer stack: https://github.com/Azure/azure-functions-host/issues/2690

I think we need to consider a design that will sometimes call process.exit, and the question is what heuristic should we use.

mathewc commented 6 years ago

The issue described here sounds like it would be addressed by https://github.com/Azure/azure-functions-host/issues/2972 as @paulbatum mentions above.