I have written a simple custom module that uses static content files (Markdown, HTML, images etc) to render content for the user within the module. The static content files are delivered in to a "drop" folder as a ZIP file, which is then unzipped into a "source" folder (which is first emptied of old files), and some processing is performed on them before they are shown in the module.
The unzipping and processing is performed by a DNN scheduled task which monitors the drop folder.
My issue is that the unzipping frequently (but not always) fails with a ThreadAbortException. Then, on the next run of the scheduled task, the unzip is attempted again and fails with a "file in use" exception as the emptying of the source folder is attempted. This cycle then repeats until a hard restart of the application pool is performed.
I assume that the problem is that the ThreadAbortException left file handles open on the files being unzipped, which are only released by closing the w3wp.exe process.
What I need to do is figure out how to avoid the ThreadAbortException, but it is intermittent and I can't see why it happens (the stack trace does not reveal much - see below, and there is nothing in the Windows Application event log).
What I have tried
1. File handles being left open is I think a consequence of the streams used to read & write the files during the unzipping (which I do with SharpZipLib) not being closed. Any place I use a Stream/FileStream I create it in a using block. However I think the ThreadAbortException does not respect this, leading to the Dispose never being called.
2. I have tried catching the ThreadAbortException and calling Thread.ResetAbort(), but this has no effect.
3. Created an HttpModule that in theory prevents application restarts when folders are deleted (which happens when the source folder is emptied). However it had no effect and the ThreadAbortException is not consistently followed by an app restart being logged (although sometimes it is). Source: https://ashishgandhi.word...a-folder-is-deleted/
DNN itself unzips new module packages, cleans temp folders etc without this happening, so I must be doing something wrong ... any advice? My only thought at this point is to try doing the unzipping in a console app process that the scheduled task spawns, so if it fails the console process closes and handles are released and it can be tried again.
Thanks
Example of 1st error (ThreadAbortException):
DocFx Module: Error un-zipping file: E:\inetpub\wwwroot\Company\DNN\Articles\_install\24570.zip Exception: Thread was being aborted. Exception Trace: (TRUNCATED TO 500 CHARS): System.Threading.ThreadAbortException: Thread was being aborted. at Microsoft.Win32.Win32Native.CreateFile(String lpFileName, Int32 dwDesiredAccess, FileShare dwShareMode, SECURITY_ATTRIBUTES securityAttrs, FileMode dwCreationDisposition, Int32 dwFlagsAndAttributes, IntPtr hTemplateFile) at Microsoft.Win32.Win32Native.SafeCreateFile(String lpFileName, Int32 dwDesiredAccess, FileShare dwShareMode, SECURITY_ATTRIBUTES securityAttrs, FileMode dwCreationDisposition, Int32 dwFlagsAndAttribute
Example of 2nd error ("file is use" exception):
DocFx Module: Error deleting existing contents of folder: E:\inetpub\wwwroot\Company\DNN\Articles\_source\General Exception: The process cannot access the file 'ImportFrom2x.html' because it is being used by another process. Exception Trace: System.IO.IOException: The process cannot access the file 'ImportFrom2x.html' because it is being used by another process. at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound, WIN32_FIND_DATA& data) at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost) at Company.DNN.DocFxSiteViewer.DocFxModuleController.DeleteFolderContents(String folderPath)
One thing you may want to consider if you can, is to utilize the out-of-the-box .NET Framework zipping rather than that of the SharpZipLib. I'f found better luck with that process (https://learn.microsoft.c...s-and-extract-files) ThreadAbort, if this is sporadic, could be an IIS Restart which if that is happeing is a pretty hard abort.
These Forums are for the discussion of the open source CMS DNN platform and ecosystem.
For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:
Awesome! Simply post in the forums using the link below and we'll get you started.