Skip to content

Commit fa7ed5a

Browse files
Fix NullReferenceException when connected to RavenDB cloud (#5112)
* Fix `NullReferenceException` when connected to RavenDB cloud which does not return memory information. * Update src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs Co-authored-by: Mauro Servienti <[email protected]> * use is null --------- Co-authored-by: Mauro Servienti <[email protected]>
1 parent b0d09fa commit fa7ed5a

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/ServiceControl.Audit.Persistence.RavenDB/CustomChecks/CheckDirtyMemory.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace ServiceControl.Audit.Persistence.RavenDB.CustomChecks;
88

99
class CheckDirtyMemory(MemoryInformationRetriever memoryInformationRetriever, ILogger<CheckDirtyMemory> logger) : CustomCheck("RavenDB dirty memory", "ServiceControl.Audit Health", TimeSpan.FromMinutes(5))
1010
{
11-
1211
public override async Task<CheckResult> PerformCheck(CancellationToken cancellationToken = default)
1312
{
1413
var (isHighDirty, dirtyMemory) = await memoryInformationRetriever.GetMemoryInformation(cancellationToken);

src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ record MemoryInformation
3131
var httpResponse = await client.GetAsync("/admin/debug/memory/stats?includeThreads=false&includeMappings=false", cancellationToken);
3232
var responseDto = JsonSerializer.Deserialize<ResponseDto>(await httpResponse.Content.ReadAsStringAsync(cancellationToken));
3333

34-
return (responseDto.MemoryInformation.IsHighDirty, responseDto.MemoryInformation.DirtyMemory);
34+
return responseDto.MemoryInformation is null
35+
? default
36+
: (responseDto.MemoryInformation.IsHighDirty, responseDto.MemoryInformation.DirtyMemory);
3537
}
3638
}

src/ServiceControl.Persistence.RavenDB/MemoryInformationRetriever.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ record MemoryInformation
3131
var httpResponse = await client.GetAsync("/admin/debug/memory/stats?includeThreads=false&includeMappings=false", cancellationToken);
3232
var responseDto = JsonSerializer.Deserialize<ResponseDto>(await httpResponse.Content.ReadAsStringAsync(cancellationToken));
3333

34-
return (responseDto.MemoryInformation.IsHighDirty, responseDto.MemoryInformation.DirtyMemory);
34+
return responseDto.MemoryInformation is null
35+
? default
36+
: (responseDto.MemoryInformation.IsHighDirty, responseDto.MemoryInformation.DirtyMemory);
3537
}
3638
}

0 commit comments

Comments
 (0)