You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tinkerpop.apache.org by dkuppitz <gi...@git.apache.org> on 2018/06/25 16:02:36 UTC

[GitHub] tinkerpop pull request #885: TINKERPOP-1978 Gremlin.Net: Add check for conne...

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.


---