Skip to content
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

Asp.net/IIS Support #42

Open
nicholasguyett opened this issue Jan 13, 2017 · 12 comments
Open

Asp.net/IIS Support #42

nicholasguyett opened this issue Jan 13, 2017 · 12 comments

Comments

@nicholasguyett
Copy link
Contributor

In issues #30 and #10, its stated that this project does not support IIS/ASP.net. This is because of of incompatibilities with the app pool recycling and the releasing of resources in non-managed code.

Is it feasible to update how those resources are managed in order to fix this issue? I'm willing to put in the effort to try and make this project compatible with the app pool recycling if I could be pointed in the direction of where these non-managed code resources are at.

@ggeurts
Copy link

ggeurts commented Feb 3, 2017

Replacing IntPtr usage in the P/Invoke calls with SafeHandle implementations may go a long way in ensuring that unmanaged resources are released on shutdown of AppDomains.

@pruiz
Copy link
Owner

pruiz commented Feb 4, 2017 via email

@nicholasguyett
Copy link
Contributor Author

@pruiz, so to make this project directly usable in an IIS project, the C++ project would have to be updated? There isn't anything on the C# end that can clean up the resources?

@pruiz
Copy link
Owner

pruiz commented Feb 7, 2017

@nicholasguyett It is not (just) an issue with regards to cleaning up resources. There's also the way each process (IIS AppPool vs wkhtmltox) work (compete) with it's internal threads management code, IIS AppPool recycling, etc.

As an example, of one of the worst cases take this one: when wkhtmltox receives some pointers to callback functions it will be invoking as conversion progresses. We can make such pointers/methods safe from collection, however, we cannot control IIS AppPool recycling (more than disabling it, which is not a great idea). So you can end up with native (wkhtmltox) code, trying to invoke a managed funcion/method, no longer existing in memory, as IIS has dumped/re-created the managed application while wkhtmltox was still working on conversion..

@nicholasguyett
Copy link
Contributor Author

Just to confirm, this project is wrapping a different wrapper (wkhtmltox)?

Top google result for this is wkhtmltox which is a nodejs project, which seems an odd choice. I did also find wkhtmltoxdotnet but that project seems barely used. Are you using one of those or a different library entirely?

@joantune
Copy link

The previous commit solved the issue for me as well. I was having trouble with the garbage collection of the callbacks and after updating the nuget packages from 1.2.4 to 1.2.7 (which I'm guessing includes this commit) it solved it for me.

So, should the next commit be the removal of the following text from Readme.md or are there any other issues with IIS?

Text to remove:

No ASP.NET/IIS Support: This has to do with the way IIS manages underlaying threads, and application pools. IIS instantiates & re-cycles pools and AppDomains from time to time, and this causes non-managed resources used by this library to not be released properly.

@pruiz
Copy link
Owner

pruiz commented May 18, 2017 via email

@rfvgyhn
Copy link

rfvgyhn commented Aug 1, 2017

Would implementing IRegisteredObject (more) for pre-.net core and ApplicationStopping for .net core help with this? This would allow for notification of when the app pool intends to reset and gives a chance to clean up and potentially block if a conversion is in progress.

@pruiz
Copy link
Owner

pruiz commented Aug 1, 2017

@rfvgyhn If there was a way to 'completely' cleanup wkhtml resources, probably yes. But the thing is, trying to dispose/stop/shutdown and then re-intialize wkhtml engine under a single running program has never worked fine in my experience, and most of the time it wont re-initialize ok, or the process will end up crashing.

@rfvgyhn
Copy link

rfvgyhn commented Aug 1, 2017

Makes sense. I'm not very familiar with wkhtmltox.

@eltiare
Copy link

eltiare commented Aug 24, 2018

Does this also apply to the .Net Core/Kestrel setup?

@pruiz
Copy link
Owner

pruiz commented Aug 25, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants