DNN Forums

Ask questions about your website to get help learning DNN and help resolve issues.

Advice on avoiding ThreadAbortException when unzipping files into DNN custom module folder via scheduled task

 1 Replies
 1 Subscribed to this topic
 26 Subscribed to this forum
Sort:
Author
Messages
New Around Here
Posts: 5
New Around Here
New Poster
New Poster
Congrats on posting!

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)

Advanced Member
Posts: 143
Advanced Member
2 Helpful Replier
Helpful Replier
Thanks for being such a helpful replier!
MVP
MVP
You're an MVP!
3 Engaged Reader
Engaged Reader
You are an engaged reader!
Avid Reader
Avid Reader
Avid Reader art thou!

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:

  1. If you have (suspected) security issues, please DO NOT post them in the forums but instead follow the official DNN security policy
  2. No Advertising. This includes the promotion of commercial and non-commercial products or services which are not directly related to DNN.
  3. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  4. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  5. No Flaming or Trolling.
  6. No Profanity, Racism, or Prejudice.
  7. Site Moderators have the final word on approving / removing a thread or post or comment.
  8. English language posting only, please.

Would you like to help us?

Awesome! Simply post in the forums using the link below and we'll get you started.

Get Involved