Jira (BOLT-1527) Unable to cleanup temp directory if Task loaded a DLL

2 views
Skip to first unread message

Kevin Reeuwijk (JIRA)

unread,
Oct 7, 2019, 5:53:04 AM10/7/19
to puppe...@googlegroups.com
Kevin Reeuwijk created an issue
 
Puppet Task Runner / Bug BOLT-1527
Unable to cleanup temp directory if Task loaded a DLL
Issue Type: Bug Bug
Assignee: Unassigned
Created: 2019/10/07 2:52 AM
Environment:

To reproduce, add this Puppet module to Bolt's Puppetfile and then run the windows_updates::install_kb task against a remote node over WinRM.

Priority: Normal Normal
Reporter: Kevin Reeuwijk

According to this article, Powershell is unable to fully unload a previously loaded DLL. The only way to unload a DLL is to end the Powershell session.

This presents a problem to Bolt as it executes (Powershell-based) Bolt Tasks in-process when connecting via WinRM. As a result, if the Bolt Task loads a Powershell module that contains a DLL during execution, that module's DLL stays loaded after the Tasks completes. This will cause Bolt's cleanup phase to show these errors is the debug log:

Executing command: Remove-Item -Force -Recurse -Path "C:\Users\Administrator\AppData\Local\Temp\chjzt3c5.ot3"
 
stdout:
stderr: Access to the path 'PSWindowsUpdate.dll' is denied.
At line:1 char:1
+ Remove-Item -Force -Recurse -Path "C:\Users\Administrator\AppData\Loc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (PSWindowsUpdate.dll:FileInfo) [Remove-Item], UnauthorizedAccessException
    + FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand
 
stdout:
stderr: The directory is not empty.At line:1 char:1
+ Remove-Item -Force -Recurse -Path "C:\Users\Administrator\AppData\Loc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (files:DirectoryInfo) [Remove-Item], IOException
    + FullyQualifiedErrorId : RemoveFileSystemItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand
 
stdout:
stderr: The directory is not empty.At line:1 char:1
+ Remove-Item -Force -Recurse -Path "C:\Users\Administrator\AppData\Loc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (windows_updates:DirectoryInfo) [Remove-Item], IOException
    + FullyQualifiedErrorId : RemoveFileSystemItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand
 
stdout:
stderr: The directory is not empty.At line:1 char:1
+ Remove-Item -Force -Recurse -Path "C:\Users\Administrator\AppData\Loc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (C:\Users\Admini...mp\chjzt3c5.ot3:DirectoryInfo) [Remove-Item], IOException
    + FullyQualifiedErrorId : RemoveFileSystemItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand
 
Command failed with exit code 5
Closed session

When checking the remote node, we can confirm that the temp directory has not been removed and the offending DLL is still remaining in it.

To mitigate this problem, Bolt should execute Powershell-based commands & Tasks in a new Powershell session, instead of its own session. That way, the child session will end after execution, causing the DLL to be unloaded. When the parent session then performs the cleanup, no access-denied issues will occur.

Running user content (commands/Tasks) in a separate process is also likely to be more robust as the parent process will remain unaffected by anything unexpected happening in the child process.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages