feat(dlp): graceful shutdown and COM cleanup for email collector

This commit is contained in:
igor04091968
2026-05-07 23:52:03 +03:00
parent ac59d44719
commit b992ad2234
+21 -1
View File
@@ -610,7 +610,8 @@ if ($useOutlook) {
# Main loop # Main loop
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
while ($true) { try {
while ($true) {
try { try {
Flush-Wal Flush-Wal
Write-CollectorHealth -Status 'running' Write-CollectorHealth -Status 'running'
@@ -651,4 +652,23 @@ while ($true) {
} }
Start-Sleep -Seconds $resolvedPollSeconds Start-Sleep -Seconds $resolvedPollSeconds
}
}
finally {
Write-CollectorHealth -Status 'stopped'
try {
if ($null -ne $script:SentFolder) {
[void][System.Runtime.InteropServices.Marshal]::ReleaseComObject($script:SentFolder)
$script:SentFolder = $null
}
if ($null -ne $script:OutlookNamespace) {
[void][System.Runtime.InteropServices.Marshal]::ReleaseComObject($script:OutlookNamespace)
$script:OutlookNamespace = $null
}
if ($null -ne $script:OutlookApp) {
[void][System.Runtime.InteropServices.Marshal]::ReleaseComObject($script:OutlookApp)
$script:OutlookApp = $null
}
}
catch {}
} }