Improve closing and removing of connections in ConnectionPool

This resolves a possible race condition.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/ef658752
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/ef658752
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/ef658752

Branch: refs/heads/TINKERPOP-1752
Commit: ef658752099e127fa1f4e3e6737a0b6f81270622
Parents: d9a4f79
Author: florianhockmann <florianhockm...@apache.org>
Authored: Wed Sep 6 20:53:11 2017 +0200
Committer: florianhockmann <florianhockm...@apache.org>
Committed: Wed Sep 6 20:53:11 2017 +0200

----------------------------------------------------------------------
 gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionPool.cs | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef658752/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionPool.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionPool.cs 
b/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionPool.cs
index 779815a..9501686 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionPool.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/ConnectionPool.cs
@@ -101,18 +101,15 @@ namespace Gremlin.Net.Driver
 
         private void RemoveAllConnections()
         {
-            while (!_connections.IsEmpty)
+            while (_connections.TryTake(out var connection))
             {
-                _connections.TryTake(out var connection);
                 connection.Dispose();
             }
         }
 
         private async Task TeardownAsync()
         {
-            var closeTasks = new List<Task>(_connections.Count);
-            closeTasks.AddRange(_connections.Select(conn => 
conn.CloseAsync()));
-            await Task.WhenAll(closeTasks).ConfigureAwait(false);
+            await Task.WhenAll(_connections.Select(c => 
c.CloseAsync())).ConfigureAwait(false);
         }
 
         #region IDisposable Support

Reply via email to