Skip to content

Commit

Permalink
Fix/leak (#434)
Browse files Browse the repository at this point in the history
* debugging

* reset comented out code and scope tests only to memory leak

* simulate a machine with precompute

* Fixed multiple memry leaks
Fixed the CI issue

* put the netstandard tests back

* update the precompute tests

* bump version to 1.91.9

* move helpers to their own file

* It doesn't matter, but still

---------

Co-authored-by: AddressXception <github@addressxception.com>
Co-authored-by: John Morgan <john.morgan@infernored.com>
  • Loading branch information
3 people committed Aug 14, 2023
1 parent 6c5f003 commit 196c90a
Show file tree
Hide file tree
Showing 11 changed files with 227 additions and 160 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ test-netstandard-x86:
ifeq ($(OPERATING_SYSTEM),Darwin)
echo "x86 builds are not supported on MacOS"
else
PROCESSOR=x86 && make test-netstandard
PROCESSOR=x86 VSPLATFORM=Win32 USE_32BIT_MATH=ON && make test-netstandard
endif

# copy the build output from the processor builds to
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;

namespace ElectionGuard.Encryption.Tests
{

public static class TestHelpers
{
public static async Task RunForAsync(TimeSpan duration)
{
var start = DateTime.Now;
var end = start + duration;
while (DateTime.Now < end)
{
PrintMemory();
await Task.Delay(1000);
}
}

public static void RunFor(TimeSpan duration)
{
var start = DateTime.Now;
var end = start + duration;
while (DateTime.Now < end)
{
PrintMemory();
Thread.Sleep(1000);
}
}

public static void PrintMemory()
{
var currentProcess = Process.GetCurrentProcess();
var workingSet = currentProcess.WorkingSet64;
Console.WriteLine($"Memory Size: {workingSet / (1024.0 * 1024.0):F2} MB");
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
Expand All @@ -11,6 +12,7 @@ public class TestPrecompute
{
private const int MaxCompleteDelay = 30000;
private const int TestBufferSize = 500;
private const int TestRunLengthInS = 10;

private PrecomputeBufferContext _precompute;
private AutoResetEvent _waitHandle;
Expand Down Expand Up @@ -48,7 +50,7 @@ public async Task Test_Precompute_Status_Running()
_precompute.StartPrecomputeAsync();
var runningStatus = _precompute.GetStatus();

await Task.Delay(500);
await TestHelpers.RunForAsync(TimeSpan.FromSeconds(1));

_precompute.StopPrecompute();

Expand All @@ -65,17 +67,25 @@ public async Task Test_Precompute_Status_Complete()
{
_precompute.StartPrecomputeAsync();

await Task.Delay(2000);
await TestHelpers.RunForAsync(TimeSpan.FromSeconds(TestRunLengthInS));

var waitReturn = _waitHandle.WaitOne();

var status = _precompute.GetStatus();
Console.WriteLine($"Completed: {status.CurrentQueueSize}");

Assert.That(status.CurrentQueueSize, Is.GreaterThanOrEqualTo(TestBufferSize));
Assert.That(status.Progress, Is.GreaterThanOrEqualTo(1.0));
Assert.AreEqual(PrecomputeState.Completed, status.CurrentState);
Assert.AreEqual(true, waitReturn);
}

[Test, Order(5)]
public void Test_Precompute_Using_Old_Interface()
{
var compute = new Precompute();
compute.StartPrecomputeAsync(_precompute.PublicKey, TestBufferSize);
TestHelpers.RunFor(TimeSpan.FromSeconds(TestRunLengthInS));
compute.StopPrecompute();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ public class PrecomputeBufferContext : DisposableBase
public event StatusEventHandler ProgressEvent;
public event StatusEventHandler CompletedEvent;

public ElementModP PublicKey => _elgamalPublicKey;

private PrecomputeStatus _currentStatus = new PrecomputeStatus
{
Progress = 0,
Expand Down
2 changes: 1 addition & 1 deletion libs/hacl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ CPMAddPackage(
NAME hacl
GITHUB_REPOSITORY addressxception/hacl-packages
VERSION 0.6.0
GIT_TAG 8b17413ea5731de2fec5c511f24d8bf85ffcf3e7
GIT_TAG 04883d6ce3384ee5c8c31db907ca556ed8b45571
OPTIONS "HACL_CUSTOM_CONFIG_FILE_PATH ${HACL_CUSTOM_CONFIG_FILE_PATH}"
)

Expand Down
Loading

0 comments on commit 196c90a

Please sign in to comment.