mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2026-02-03 04:09:29 -05:00
Various memory leak fixes and improvements
This commit is contained in:
parent
3a32511685
commit
c3d3627634
12 changed files with 62 additions and 57 deletions
38
.github/ISSUE_TEMPLATE/create-new-issue.md
vendored
38
.github/ISSUE_TEMPLATE/create-new-issue.md
vendored
|
|
@ -1,38 +0,0 @@
|
||||||
---
|
|
||||||
name: Create new issue
|
|
||||||
about: Create a detailed issue to help us to fix them
|
|
||||||
labels:
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
<!--- Provide a general summary of the issue in the Title above -->
|
|
||||||
|
|
||||||
## Expected Behavior
|
|
||||||
<!--- If you're describing a bug, tell us what should happen -->
|
|
||||||
<!--- If you're suggesting a change/improvement, tell us how it should work -->
|
|
||||||
|
|
||||||
## Current Behavior
|
|
||||||
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
|
|
||||||
<!--- If suggesting a change/improvement, explain the difference from current behavior -->
|
|
||||||
|
|
||||||
## Possible Solution
|
|
||||||
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
|
|
||||||
<!--- or ideas how to implement: the addition or change -->
|
|
||||||
|
|
||||||
## Steps to Reproduce (for bugs)
|
|
||||||
<!--- Provide a link to a live example, or an unambiguous set of steps to -->
|
|
||||||
<!--- reproduce this bug. Include configuration, logs, etc. to reproduce, if relevant -->
|
|
||||||
1.
|
|
||||||
2.
|
|
||||||
3.
|
|
||||||
4.
|
|
||||||
|
|
||||||
## Context
|
|
||||||
<!--- How has this issue affected you? What are you trying to accomplish? -->
|
|
||||||
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
|
|
||||||
|
|
||||||
## Your Environment
|
|
||||||
<!--- Include as many relevant details about the environment you experienced the problem in -->
|
|
||||||
* PowerShell Version used (`$PSVersionTable.PSVersion`):
|
|
||||||
|
|
||||||
* Operating System and version (`Get-IcingaWindowsInformation Win32_OperatingSystem | Select-Object Version, BuildNumber, Caption`):
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -8,6 +8,7 @@ cache/*
|
||||||
*.log
|
*.log
|
||||||
*.pfx
|
*.pfx
|
||||||
*.dll
|
*.dll
|
||||||
|
*.DS_Store
|
||||||
|
|
||||||
# JEA
|
# JEA
|
||||||
RoleCapabilities/IcingaForWindows.psrc
|
RoleCapabilities/IcingaForWindows.psrc
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
||||||
* [#673](https://github.com/Icinga/icinga-powershell-framework/pull/673) Fixes a memory leak while fetching Windows EventLog information by using CLI tools and inside the Hyper-V provide
|
* [#673](https://github.com/Icinga/icinga-powershell-framework/pull/673) Fixes a memory leak while fetching Windows EventLog information by using CLI tools and inside the Hyper-V provide
|
||||||
|
* [#678](https://github.com/Icinga/icinga-powershell-framework/pull/678) Fixes various memory leaks in Icinga for Windows API core and check handler
|
||||||
|
|
||||||
## 1.11.1 (2023-11-07)
|
## 1.11.1 (2023-11-07)
|
||||||
|
|
||||||
|
|
|
||||||
5
lib/core/cache/Get-IcingaCacheData.psm1
vendored
5
lib/core/cache/Get-IcingaCacheData.psm1
vendored
|
|
@ -33,7 +33,8 @@ function Get-IcingaCacheData()
|
||||||
[string]$Space,
|
[string]$Space,
|
||||||
[string]$CacheStore,
|
[string]$CacheStore,
|
||||||
[string]$KeyName,
|
[string]$KeyName,
|
||||||
[switch]$TempFile = $FALSE
|
[switch]$TempFile = $FALSE,
|
||||||
|
[switch]$AsObject = $FALSE
|
||||||
);
|
);
|
||||||
|
|
||||||
$CacheFile = Join-Path -Path (Join-Path -Path (Join-Path -Path (Get-IcingaCacheDir) -ChildPath $Space) -ChildPath $CacheStore) -ChildPath ([string]::Format('{0}.json', $KeyName));
|
$CacheFile = Join-Path -Path (Join-Path -Path (Join-Path -Path (Get-IcingaCacheDir) -ChildPath $Space) -ChildPath $CacheStore) -ChildPath ([string]::Format('{0}.json', $KeyName));
|
||||||
|
|
@ -62,7 +63,7 @@ function Get-IcingaCacheData()
|
||||||
return $null;
|
return $null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([string]::IsNullOrEmpty($KeyName)) {
|
if ($AsObject -Or [string]::IsNullOrEmpty($KeyName)) {
|
||||||
return $cacheData;
|
return $cacheData;
|
||||||
} else {
|
} else {
|
||||||
return $cacheData.$KeyName;
|
return $cacheData.$KeyName;
|
||||||
|
|
|
||||||
2
lib/core/cache/Set-IcingaCacheData.psm1
vendored
2
lib/core/cache/Set-IcingaCacheData.psm1
vendored
|
|
@ -43,7 +43,7 @@ function Set-IcingaCacheData()
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((Test-Path $CacheFile)) {
|
if ((Test-Path $CacheFile)) {
|
||||||
$cacheData = Get-IcingaCacheData -Space $Space -CacheStore $CacheStore;
|
$cacheData = Get-IcingaCacheData -Space $Space -CacheStore $CacheStore -KeyName $KeyName -AsObject;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
New-Item -ItemType File -Path $CacheTmpFile -Force -ErrorAction Stop | Out-Null;
|
New-Item -ItemType File -Path $CacheTmpFile -Force -ErrorAction Stop | Out-Null;
|
||||||
|
|
|
||||||
|
|
@ -18,4 +18,6 @@ function Write-IcingaDebugMessage()
|
||||||
$DebugContent += $Objects;
|
$DebugContent += $Objects;
|
||||||
|
|
||||||
Write-IcingaEventMessage -EventId 1000 -Namespace 'Debug' -ExceptionObject $ExceptionObject -Objects $DebugContent;
|
Write-IcingaEventMessage -EventId 1000 -Namespace 'Debug' -ExceptionObject $ExceptionObject -Objects $DebugContent;
|
||||||
|
|
||||||
|
$DebugContent = $null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ function Test-IcingaRESTClientConnection()
|
||||||
-Client $Connection.Client `
|
-Client $Connection.Client `
|
||||||
-ClientList $Global:Icinga.Public.Daemons.RESTApi.ClientBlacklist;
|
-ClientList $Global:Icinga.Public.Daemons.RESTApi.ClientBlacklist;
|
||||||
Write-IcingaEventMessage -EventId 1501 -Namespace 'Framework' -Objects $Connection.Client.Client;
|
Write-IcingaEventMessage -EventId 1501 -Namespace 'Framework' -Objects $Connection.Client.Client;
|
||||||
Close-IcingaTCPConnection -Client $Connection.Client;
|
Close-IcingaTCPConnection -Connection $Connection;
|
||||||
$Connection = $null;
|
$Connection = $null;
|
||||||
return $FALSE;
|
return $FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,9 +84,15 @@ function New-IcingaForWindowsRESTApi()
|
||||||
-Client (New-IcingaTCPClient -Socket $Socket) `
|
-Client (New-IcingaTCPClient -Socket $Socket) `
|
||||||
-Certificate $Certificate;
|
-Certificate $Certificate;
|
||||||
|
|
||||||
|
if ($Connection.Client -eq $null -Or $Connection.Stream -eq $null) {
|
||||||
|
Close-IcingaTCPConnection -Connection $Connection;
|
||||||
|
$Connection = $null;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (Test-IcingaRESTClientBlacklisted -Client $Connection.Client -ClientList $Global:Icinga.Public.Daemons.RESTApi.ClientBlacklist) {
|
if (Test-IcingaRESTClientBlacklisted -Client $Connection.Client -ClientList $Global:Icinga.Public.Daemons.RESTApi.ClientBlacklist) {
|
||||||
Write-IcingaDebugMessage -Message 'A remote client which is trying to connect was blacklisted' -Objects $Connection.Client.Client;
|
Write-IcingaDebugMessage -Message 'A remote client which is trying to connect was blacklisted' -Objects $Connection.Client.Client;
|
||||||
Close-IcingaTCPConnection -Client $Connection.Client;
|
Close-IcingaTCPConnection -Connection $Connection;
|
||||||
$Connection = $null;
|
$Connection = $null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -98,7 +104,7 @@ function New-IcingaForWindowsRESTApi()
|
||||||
|
|
||||||
# API not yet ready
|
# API not yet ready
|
||||||
if ($Global:Icinga.Public.Daemons.RESTApi.ApiRequests.Count -eq 0) {
|
if ($Global:Icinga.Public.Daemons.RESTApi.ApiRequests.Count -eq 0) {
|
||||||
Close-IcingaTCPConnection -Client $Connection.Client;
|
Close-IcingaTCPConnection -Connection $Connection;
|
||||||
$Connection = $null;
|
$Connection = $null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -107,7 +113,7 @@ function New-IcingaForWindowsRESTApi()
|
||||||
$NextRESTApiThreadId = (Get-IcingaNextRESTApiThreadId);
|
$NextRESTApiThreadId = (Get-IcingaNextRESTApiThreadId);
|
||||||
|
|
||||||
if ($Global:Icinga.Public.Daemons.RESTApi.ApiRequests.ContainsKey($NextRESTApiThreadId) -eq $FALSE) {
|
if ($Global:Icinga.Public.Daemons.RESTApi.ApiRequests.ContainsKey($NextRESTApiThreadId) -eq $FALSE) {
|
||||||
Close-IcingaTCPConnection -Client $Connection.Client;
|
Close-IcingaTCPConnection -Connection $Connection;
|
||||||
$Connection = $null;
|
$Connection = $null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ function New-IcingaForWindowsRESTThread()
|
||||||
# Send the authentication prompt
|
# Send the authentication prompt
|
||||||
Send-IcingaWebAuthMessage -Connection $Connection;
|
Send-IcingaWebAuthMessage -Connection $Connection;
|
||||||
# Close the connection
|
# Close the connection
|
||||||
Close-IcingaTCPConnection -Client $Connection.Client;
|
Close-IcingaTCPConnection -Connection $Connection;
|
||||||
$Connection = $null;
|
$Connection = $null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -56,14 +56,14 @@ function New-IcingaForWindowsRESTThread()
|
||||||
# Re-send the authentication prompt
|
# Re-send the authentication prompt
|
||||||
Send-IcingaWebAuthMessage -Connection $Connection;
|
Send-IcingaWebAuthMessage -Connection $Connection;
|
||||||
# Close the connection
|
# Close the connection
|
||||||
Close-IcingaTCPConnection -Client $Connection.Client;
|
Close-IcingaTCPConnection -Connection $Connection;
|
||||||
$Connection = $null;
|
$Connection = $null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set our thread being active
|
# Set our thread being active
|
||||||
Set-IcingaForWindowsThreadAlive -ThreadName $Global:Icinga.Protected.ThreadName -Active -TerminateAction @{ 'Command' = 'Close-IcingaTCPConnection'; 'Arguments' = @{ 'Client' = $Connection.Client } };
|
Set-IcingaForWindowsThreadAlive -ThreadName $Global:Icinga.Protected.ThreadName -Active -TerminateAction @{ 'Command' = 'Close-IcingaTCPConnection'; 'Arguments' = @{ 'Connection' = $Connection } };
|
||||||
|
|
||||||
# We should remove clients from the blacklist who are sending valid requests
|
# We should remove clients from the blacklist who are sending valid requests
|
||||||
Remove-IcingaRESTClientBlacklist -Client $Connection.Client -ClientList $Global:Icinga.Public.Daemons.RESTApi.ClientBlacklist;
|
Remove-IcingaRESTClientBlacklist -Client $Connection.Client -ClientList $Global:Icinga.Public.Daemons.RESTApi.ClientBlacklist;
|
||||||
|
|
@ -100,7 +100,7 @@ function New-IcingaForWindowsRESTThread()
|
||||||
|
|
||||||
# Finally close the clients connection as we are done here and
|
# Finally close the clients connection as we are done here and
|
||||||
# ensure this thread will close by simply leaving the function
|
# ensure this thread will close by simply leaving the function
|
||||||
Close-IcingaTCPConnection -Client $Connection.Client;
|
Close-IcingaTCPConnection -Connection $Connection;
|
||||||
$Connection = $null;
|
$Connection = $null;
|
||||||
|
|
||||||
# Force Icinga for Windows Garbage Collection
|
# Force Icinga for Windows Garbage Collection
|
||||||
|
|
|
||||||
|
|
@ -40,11 +40,17 @@ function New-IcingaCheckResult()
|
||||||
|
|
||||||
Set-IcingaInternalPluginExitCode -ExitCode $ExitCode;
|
Set-IcingaInternalPluginExitCode -ExitCode $ExitCode;
|
||||||
|
|
||||||
|
$this.Check = $null;
|
||||||
|
|
||||||
return $ExitCode;
|
return $ExitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($Compile) {
|
if ($Compile) {
|
||||||
return $IcingaCheckResult.Compile();
|
$IcingaExitCode = $IcingaCheckResult.Compile();
|
||||||
|
$IcingaCheckResult = $null;
|
||||||
|
$Check = $null;
|
||||||
|
|
||||||
|
return $IcingaExitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $IcingaCheckResult;
|
return $IcingaCheckResult;
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,40 @@
|
||||||
function Close-IcingaTCPConnection()
|
function Close-IcingaTCPConnection()
|
||||||
{
|
{
|
||||||
param(
|
param(
|
||||||
[System.Net.Sockets.TcpClient]$Client = $null
|
[hashtable]$Connection = @{ }
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($null -eq $Client) {
|
if ($null -eq $Connection -Or $Connection.Count -eq 0) {
|
||||||
|
$Connection = $null;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-IcingaDebugMessage -Message (
|
Write-IcingaDebugMessage -Message (
|
||||||
[string]::Format(
|
[string]::Format(
|
||||||
'Closing client connection for endpoint {0}',
|
'Closing client connection for endpoint {0}',
|
||||||
(Get-IcingaTCPClientRemoteEndpoint -Client $Client)
|
(Get-IcingaTCPClientRemoteEndpoint -Client $Connection.Client)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$Client.Close();
|
try {
|
||||||
$Client.Dispose();
|
if ($null -ne $Connection.Stream) {
|
||||||
$Client = $null;
|
$Connection.Stream.Close();
|
||||||
|
$Connection.Stream.Dispose();
|
||||||
|
$Connection.Stream = $null;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
$Connection.Stream = $null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if ($null -ne $Connection.Client) {
|
||||||
|
$Connection.Client.Close();
|
||||||
|
$Connection.Client.Dispose();
|
||||||
|
$Connection.Client = $null;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
$Connection.Client = $null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$Connection = $null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,17 @@ function New-IcingaSSLStream()
|
||||||
return $null;
|
return $null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[System.Net.Security.SslStream]$SSLStream = $null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$SSLStream = New-Object System.Net.Security.SslStream($Client.GetStream(), $false)
|
$SSLStream = New-Object System.Net.Security.SslStream($Client.GetStream(), $false);
|
||||||
$SSLStream.AuthenticateAsServer($Certificate, $false, [System.Security.Authentication.SslProtocols]::Tls12, $true) | Out-Null;
|
$SSLStream.AuthenticateAsServer($Certificate, $false, [System.Security.Authentication.SslProtocols]::Tls12, $true) | Out-Null;
|
||||||
} catch {
|
} catch {
|
||||||
|
if ($null -ne $SSLStream) {
|
||||||
|
$SSLStream.Close();
|
||||||
|
$SSLStream.Dispose();
|
||||||
|
$SSLStream = $null;
|
||||||
|
}
|
||||||
Write-IcingaEventMessage -EventId 1500 -Namespace 'Framework' -ExceptionObject $_ -Objects $Client.Client;
|
Write-IcingaEventMessage -EventId 1500 -Namespace 'Framework' -ExceptionObject $_ -Objects $Client.Client;
|
||||||
return $null;
|
return $null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue