From ab6e3390d91515d4d6b8491d517258970b32c83f Mon Sep 17 00:00:00 2001 From: Ramon Smits Date: Mon, 8 Sep 2025 16:33:01 +0200 Subject: [PATCH 1/3] Fix `NullReferenceException` when connected to RavenDB cloud which does not return memory information. --- .../CustomChecks/CheckDirtyMemory.cs | 1 - .../MemoryInformationRetriever.cs | 4 +++- .../MemoryInformationRetriever.cs | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ServiceControl.Audit.Persistence.RavenDB/CustomChecks/CheckDirtyMemory.cs b/src/ServiceControl.Audit.Persistence.RavenDB/CustomChecks/CheckDirtyMemory.cs index 85b02e55c5..1a81f67bee 100644 --- a/src/ServiceControl.Audit.Persistence.RavenDB/CustomChecks/CheckDirtyMemory.cs +++ b/src/ServiceControl.Audit.Persistence.RavenDB/CustomChecks/CheckDirtyMemory.cs @@ -8,7 +8,6 @@ namespace ServiceControl.Audit.Persistence.RavenDB.CustomChecks; class CheckDirtyMemory(MemoryInformationRetriever memoryInformationRetriever, ILogger logger) : CustomCheck("RavenDB dirty memory", "ServiceControl.Audit Health", TimeSpan.FromMinutes(5)) { - public override async Task PerformCheck(CancellationToken cancellationToken = default) { var (isHighDirty, dirtyMemory) = await memoryInformationRetriever.GetMemoryInformation(cancellationToken); diff --git a/src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs b/src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs index 5aff8c0fb7..66dcada990 100644 --- a/src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs +++ b/src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs @@ -31,6 +31,8 @@ record MemoryInformation var httpResponse = await client.GetAsync("/admin/debug/memory/stats?includeThreads=false&includeMappings=false", cancellationToken); var responseDto = JsonSerializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(cancellationToken)); - return (responseDto.MemoryInformation.IsHighDirty, responseDto.MemoryInformation.DirtyMemory); + return null == responseDto.MemoryInformation + ? default + : (responseDto.MemoryInformation.IsHighDirty, responseDto.MemoryInformation.DirtyMemory); } } \ No newline at end of file diff --git a/src/ServiceControl.Persistence.RavenDB/MemoryInformationRetriever.cs b/src/ServiceControl.Persistence.RavenDB/MemoryInformationRetriever.cs index f7db4f2557..ed34ab381f 100644 --- a/src/ServiceControl.Persistence.RavenDB/MemoryInformationRetriever.cs +++ b/src/ServiceControl.Persistence.RavenDB/MemoryInformationRetriever.cs @@ -31,6 +31,8 @@ record MemoryInformation var httpResponse = await client.GetAsync("/admin/debug/memory/stats?includeThreads=false&includeMappings=false", cancellationToken); var responseDto = JsonSerializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(cancellationToken)); - return (responseDto.MemoryInformation.IsHighDirty, responseDto.MemoryInformation.DirtyMemory); + return null == responseDto.MemoryInformation + ? default + : (responseDto.MemoryInformation.IsHighDirty, responseDto.MemoryInformation.DirtyMemory); } } \ No newline at end of file From 190431fc20b7d2c8d231e23f93ee0b6dedbba5d4 Mon Sep 17 00:00:00 2001 From: Ramon Smits Date: Tue, 9 Sep 2025 17:42:23 +0200 Subject: [PATCH 2/3] Update src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs Co-authored-by: Mauro Servienti --- .../MemoryInformationRetriever.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs b/src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs index 66dcada990..3564d1bcb3 100644 --- a/src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs +++ b/src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs @@ -31,7 +31,7 @@ record MemoryInformation var httpResponse = await client.GetAsync("/admin/debug/memory/stats?includeThreads=false&includeMappings=false", cancellationToken); var responseDto = JsonSerializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(cancellationToken)); - return null == responseDto.MemoryInformation + return responseDto.MemoryInformation is null ? default : (responseDto.MemoryInformation.IsHighDirty, responseDto.MemoryInformation.DirtyMemory); } From 2d554cc640a97dfd9ef6a4d9bb1ed302b0b8b414 Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Tue, 9 Sep 2025 18:24:16 +0200 Subject: [PATCH 3/3] use is null --- .../MemoryInformationRetriever.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ServiceControl.Persistence.RavenDB/MemoryInformationRetriever.cs b/src/ServiceControl.Persistence.RavenDB/MemoryInformationRetriever.cs index ed34ab381f..4e24e98ede 100644 --- a/src/ServiceControl.Persistence.RavenDB/MemoryInformationRetriever.cs +++ b/src/ServiceControl.Persistence.RavenDB/MemoryInformationRetriever.cs @@ -31,7 +31,7 @@ record MemoryInformation var httpResponse = await client.GetAsync("/admin/debug/memory/stats?includeThreads=false&includeMappings=false", cancellationToken); var responseDto = JsonSerializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(cancellationToken)); - return null == responseDto.MemoryInformation + return responseDto.MemoryInformation is null ? default : (responseDto.MemoryInformation.IsHighDirty, responseDto.MemoryInformation.DirtyMemory); }