Github user dkuppitz commented on a diff in the pull request:
https://github.com/apache/tinkerpop/pull/885#discussion_r197851424
--- Diff: gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionPool.cs ---
@@ -45,19 +44,28 @@ public ConnectionPool(ConnectionFactory
connectionFactory)
public async Task<IConnection> GetAvailableConnectionAsync()
{
- Connection connection = null;
- lock (_connectionsLock)
- {
- if (!_connections.IsEmpty)
- _connections.TryTake(out connection);
- }
-
- if (connection == null)
+ if (!TryGetConnectionFromPool(out var connection))
connection = await
CreateNewConnectionAsync().ConfigureAwait(false);
return new ProxyConnection(connection, AddConnectionIfOpen);
}
+ private bool TryGetConnectionFromPool(out Connection connection)
+ {
+ while (true)
+ {
+ connection = null;
+ lock (_connectionsLock)
+ {
+ if (_connections.IsEmpty) return false;
+ _connections.TryTake(out connection);
+ }
+
+ if (connection.IsOpen) return true;
+ connection.Dispose();
--- End diff --
Won't that lead to a never-ending loop? I'm assuming that
`connection.Dispose()` won't remove it from the `_connections` collection, but
I might be wrong.
---