Auto Encryption C# driver error - Unknown port being picked in code

Hi,

We are trying to implement the auto encryption feature in our project. Whenever we configure the settings for auto encryption and try to run the code, we receive the following error:

Encryption related exception: A timeout occured after 1000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "3", ConnectionMode : "Automatic", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 3, EndPoint : "Unspecified/localhost:27020" }", EndPoint: "Unspecified/localhost:27020", State: "Disconnected", Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:27020
   at System.Net.Sockets.Socket.InternalEndConnect(IAsyncResult asyncResult)
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MongoDB.Driver.Core.Connections.TcpStreamFactory.<ConnectAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MongoDB.Driver.Core.Connections.TcpStreamFactory.<CreateStreamAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__51.MoveNext()
   --- End of inner exception stack trace ---
   at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__51.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at MongoDB.Driver.Core.Servers.ServerMonitor.<HeartbeatAsync>d__28.MoveNext()", LastUpdateTimestamp: "2020-05-11T11:34:53.7029821Z" }] }.."

We have setup a replicaset on our machine with port 27017 and 27108 as primary and secondary. We have no idea from where port 27020 is being called. If we don’t use the auto encryption library, then there is no error. Port ‘27020’ is not mentioned anywhere in our files.

It seems to be some in built issue in MongoDB encryption.

Welcome to the community @b_singh,

Automatic Client-Side Field Level Encryption requires MongoDB Enterprise 4.2 or newer or a MongoDB Atlas 4.2+ cluster. The Enterprise package includes a mongocryptd binary which runs on port 27020 by default. Drivers will attempt to spawn mongocryptd if it isn’t running already. You can set specific options include the spawn path and mongodcryptdURI in the driver options.

For more information on using automatic encryption with the .NET driver, see Client-Side Field Level Encryption in the driver documentation.

Regards,
Stennie

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.