Hello,
I'm posting this here since I don't have reporting permissions in the bug tracker.
Problem description: authenticating with invalid credentials always timeouts after 30 seconds with error: A timeout occurred after 30000ms selecting a server using CompositeServerSelector.
Steps to reproduce:
1. Start database server with command: "mongod --dbpath data --auth -v". Use empty database.
2. Create a console application in Visual Studio with the attached Program.cs. This connects to the admin database with username/password and executes a ping command.
3. Run the program.
Observed results: The ping command freezes for 30 seconds until it timeouts. Attempts to set any/all timeouts in MongoClientSettings make no difference. From the mongod log you can see that the client is repeatedly attempting to reconnect during the 30 second period.
Expected results: The client should attempt to login once. Once it detects that the credentials are invalid it should immediatelly cause an exception that indicates the correct error cause. It shouldn't be a TimeoutException but something more relevant to indicate that it was an credential problem.
Discussion: I didn't try to debug but by browsing the implementation I'm suspecting the problem is in ExclusiveConnectionPool.EnsureMinSizeAsync. That method has a loop which keeps opening new connections until enough connections are open (based on settings). But if there's an error when the connection is created it just keeps on looping and retrying. Meanwhile elsewhere we are waiting to get a connection from the pool but none are available so we're stuck until there's a timeout.