diogodamiani / IdentityServer4.Contrib.MongoDB

MongoDB persistence layer for IdentityServer4
Apache License 2.0
111 stars 58 forks source link

TimeOut connection in version 2.3.4 (2.3.3 have no problem) #45

Open ghost opened 3 years ago

ghost commented 3 years ago

Hi, I use your library In my project (.net core 3.1). I update it from 2.3.3 version to 2.3.4. In 2.3.4 in development mode this exception it is raised when the application start:

Exception thrown: 'System.TimeoutException' in MongoDB.Driver.Core.dll
An exception of type 'System.TimeoutException' occurred in MongoDB.Driver.Core.dll but was not handled in user code
A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "2", ConnectionMode : "Automatic", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 2, EndPoint : "Unspecified/s-my-server-mongo:27017" }", EndPoint: "Unspecified/s-my-server-mongo:27017", ReasonChanged: "Heartbeat", State: "Disconnected", ServerVersion: , TopologyVersion: , Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server.
 ---> System.IO.IOException: Unable to read data from the transport connection: Connessione in corso interrotta forzatamente dall'host remoto..
 ---> System.Net.Sockets.SocketException (10054): Connessione in corso interrotta forzatamente dall'host remoto.
   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.GetResult(Int16 token)
   at System.Net.FixedSizeReader.ReadPacketAsync(Stream transport, AsyncProtocolRequest request)
   at System.Net.Security.SslStream.EndProcessAuthentication(IAsyncResult result)
   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 MongoDB.Driver.Core.Connections.SslStreamFactory.CreateStreamAsync(EndPoint endPoint, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Servers.ServerMonitor.InitializeConnectionAsync(CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Servers.ServerMonitor.HeartbeatAsync(CancellationToken cancellationToken)", LastHeartbeatTimestamp: "2021-04-14T09:22:13.1362689Z", LastUpdateTimestamp: "2021-04-14T09:22:13.1362690Z" }] }.

my connection string is: mongodb://s-my-server-mongo:27017

It has no auth parameter (it's a server unreachable from outside). I pass also the Database name

.AddOperationalStore(opt => { 
                    opt.ConnectionString = "mongodb://s-my-server-mongo:27017";
                    opt.Database = "TestIdentityDb";
                    })

So I don't understand why there is this row: EndPoint : "Unspecified/s-my-server-mongo:27017"

I revert to 2.3.3 at the moment. Note I also update the mongo.db.driver (i use the latest version available 2.12.2)