Skip to content

Commit 2decc43

Browse files
authored
CSHARP-5424: Fix mongocryptdClient instantiation on AutoEncryptionLibMongoCryptController.Dispose (#1556)
1 parent e93dd86 commit 2decc43

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/MongoDB.Driver.Encryption/AutoEncryptionLibMongoController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public void Dispose()
300300
ClusterRegistry.Instance.UnregisterAndDisposeCluster(_internalClient.Cluster);
301301
}
302302

303-
if (_mongocryptdClient != null)
303+
if (_mongocryptdClient.IsValueCreated)
304304
{
305305
ClusterRegistry.Instance.UnregisterAndDisposeCluster(_mongocryptdClient.Value.Cluster);
306306
}

tests/MongoDB.Driver.Tests/Specifications/client-side-encryption/prose-tests/ClientEncryptionProseTests.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -353,26 +353,26 @@ public void BypassMongocryptdClientWhenSharedLibraryTest(
353353
try
354354
{
355355
tcpListener = new TcpListener(mongocryptdIpAddress, port: mongocryptPort);
356-
var listenerThread = new Thread(new ParameterizedThreadStart(ThreadStart)) { IsBackground = true };
356+
tcpListener.Start();
357+
var listenerThread = new Thread(ThreadStart) { IsBackground = true };
358+
listenerThread.Start(tcpListener);
357359

358360
using (var clientEncrypted = ConfigureClientEncrypted(kmsProviderFilter: "local", extraOptions: extraOptions))
359361
{
360362
var coll = GetCollection(clientEncrypted, __collCollectionNamespace);
361363

362-
listenerThread.Start(tcpListener);
363-
364364
_ = Record.Exception(() => Insert(coll, async, new BsonDocument("unencrypted", "test")));
365+
}
365366

366-
if (listenerThread.Join(timeout))
367-
{
368-
// This exception is never thrown when mognocryptd mongoClient is not spawned which is expected behavior.
369-
// However, if we intentionally break that logic to spawn mongocryptd mongoClient regardless of shared library,
370-
// this exception sometimes won't be thrown. In all such cases the spent time in listenerThread.Join is higher
371-
// or really close to timeout. So it's unclear why Join doesn't throw in that cases, but that logic is unrelated
372-
// to the driver and csfle in particular. We rely on the fact that even if we break this logic,
373-
// we run this test more than once.
374-
throw new Exception($"Listener accepted a tcp call for moncgocryptd during {timeout}.");
375-
}
367+
if (listenerThread.Join(timeout))
368+
{
369+
// This exception is never thrown when mognocryptd mongoClient is not spawned which is expected behavior.
370+
// However, if we intentionally break that logic to spawn mongocryptd mongoClient regardless of shared library,
371+
// this exception sometimes won't be thrown. In all such cases the spent time in listenerThread.Join is higher
372+
// or really close to timeout. So it's unclear why Join doesn't throw in that cases, but that logic is unrelated
373+
// to the driver and csfle in particular. We rely on the fact that even if we break this logic,
374+
// we run this test more than once.
375+
throw new Exception($"Listener accepted a tcp call for moncgocryptd during {timeout}.");
376376
}
377377
}
378378
finally
@@ -385,7 +385,6 @@ void ThreadStart(object param)
385385
try
386386
{
387387
var tcpListener = (TcpListener)param;
388-
tcpListener.Start();
389388
using var client = tcpListener.AcceptTcpClient();
390389
// Perform a blocking call to accept requests.
391390
// if we're here, then something queries port 27030.

0 commit comments

Comments
 (0)