Skip to content

Commit 36e6228

Browse files
CSHARP-3191: driver tries to run getLastError on mongocryptd that does not exists. (#827)
1 parent 0a8eded commit 36e6228

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/MongoDB.Driver.Core/Core/Connections/ConnectionInitializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public ConnectionDescription Authenticate(IConnection connection, ConnectionDesc
5959
{
6060
description = UpdateConnectionIdWithServerValue(description, connectionIdServerValue.Value);
6161
}
62-
else
62+
else if (!description.HelloResult.IsMongocryptd) // mongocryptd doesn't provide ConnectionId
6363
{
6464
try
6565
{
@@ -90,7 +90,7 @@ public async Task<ConnectionDescription> AuthenticateAsync(IConnection connectio
9090
{
9191
description = UpdateConnectionIdWithServerValue(description, connectionIdServerValue.Value);
9292
}
93-
else
93+
else if (!description.HelloResult.IsMongocryptd) // mongocryptd doesn't provide ConnectionId
9494
{
9595
try
9696
{

src/MongoDB.Driver.Core/Core/Connections/HelloResult.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ public bool IsArbiter
124124
get { return ServerType == ServerType.ReplicaSetArbiter; }
125125
}
126126

127+
/// <summary>
128+
/// Gets a value indicating whether this instance is a mongocryptd.
129+
/// </summary>
130+
/// <value>
131+
/// <c>true</c> if this instance is a mongocryptd; otherwise, <c>false</c>.
132+
/// </value>
133+
public bool IsMongocryptd => _wrapped.TryGetValue("iscryptd", out var isCryptd) && isCryptd.IsBoolean ? isCryptd.ToBoolean() : false;
134+
127135
/// <summary>
128136
/// Gets a value indicating whether this instance is a replica set member.
129137
/// </summary>

tests/MongoDB.Driver.Core.Tests/Core/Connections/HelloResultTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System.Net;
1818
using FluentAssertions;
1919
using MongoDB.Bson;
20+
using MongoDB.Bson.TestHelpers.XunitExtensions;
2021
using MongoDB.Driver.Core.Clusters;
2122
using MongoDB.Driver.Core.Compression;
2223
using MongoDB.Driver.Core.Misc;
@@ -318,5 +319,19 @@ public void HelloOk_should_return_false_when_response_does_not_contain_helloOk()
318319
var subject = new HelloResult(doc);
319320
subject.HelloOk.Should().BeFalse();
320321
}
322+
323+
[Theory]
324+
[ParameterAttributeData]
325+
public void IsMongocryptd_should_return_expected_result([Values(false, true, null)] bool? isMongocryptd)
326+
{
327+
var helloResultDocument = new BsonDocument
328+
{
329+
{ "iscryptd", () => isMongocryptd.Value, isMongocryptd.HasValue }
330+
};
331+
332+
var subject = new HelloResult(helloResultDocument);
333+
334+
subject.IsMongocryptd.Should().Be(isMongocryptd.GetValueOrDefault());
335+
}
321336
}
322337
}

0 commit comments

Comments
 (0)