You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by fl...@apache.org on 2023/05/09 06:59:54 UTC

[tinkerpop] branch TINKERPOP-2944 updated (26c6aad4b4 -> 27f7dbd960)

This is an automated email from the ASF dual-hosted git repository.

florianhockmann pushed a change to branch TINKERPOP-2944
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


 discard 26c6aad4b4 TINKERPOP-2944 Dispose Cancellation callbacks
     add 2ee47f203f Bump to 3.5.7-SNAPSHOT CTR
     new 27f7dbd960 TINKERPOP-2944 Dispose Cancellation callbacks

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (26c6aad4b4)
            \
             N -- N -- N   refs/heads/TINKERPOP-2944 (27f7dbd960)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 docs/src/upgrade/release-3.5.x.asciidoc                        | 10 ++++++++++
 gremlin-archetype/gremlin-archetype-dsl/pom.xml                |  2 +-
 gremlin-archetype/gremlin-archetype-server/pom.xml             |  2 +-
 gremlin-archetype/gremlin-archetype-tinkergraph/pom.xml        |  2 +-
 gremlin-archetype/pom.xml                                      |  2 +-
 gremlin-console/bin/gremlin.sh                                 |  2 +-
 gremlin-console/pom.xml                                        |  2 +-
 gremlin-core/pom.xml                                           |  2 +-
 gremlin-dotnet/pom.xml                                         |  2 +-
 .../src/Gremlin.Net.Template/Gremlin.Net.Template.csproj       |  2 +-
 .../src/Gremlin.Net.Template/Gremlin.Net.Template.nuspec       |  2 +-
 gremlin-dotnet/src/Gremlin.Net/Gremlin.Net.csproj              |  2 +-
 gremlin-dotnet/src/pom.xml                                     |  2 +-
 gremlin-dotnet/test/pom.xml                                    |  2 +-
 gremlin-driver/pom.xml                                         |  2 +-
 gremlin-go/pom.xml                                             |  2 +-
 gremlin-groovy/pom.xml                                         |  2 +-
 gremlin-javascript/pom.xml                                     |  2 +-
 .../src/main/javascript/gremlin-javascript/package-lock.json   |  2 +-
 .../src/main/javascript/gremlin-javascript/package.json        |  2 +-
 gremlin-language/pom.xml                                       |  2 +-
 gremlin-python/pom.xml                                         |  2 +-
 gremlin-server/pom.xml                                         |  2 +-
 gremlin-shaded/pom.xml                                         |  2 +-
 gremlin-test/pom.xml                                           |  2 +-
 gremlin-tools/gremlin-benchmark/pom.xml                        |  2 +-
 gremlin-tools/gremlin-coverage/pom.xml                         |  2 +-
 gremlin-tools/gremlin-io-test/pom.xml                          |  2 +-
 gremlin-tools/pom.xml                                          |  2 +-
 gremlint/package-lock.json                                     |  2 +-
 gremlint/package.json                                          |  2 +-
 gremlint/pom.xml                                               |  2 +-
 hadoop-gremlin/pom.xml                                         |  2 +-
 neo4j-gremlin/pom.xml                                          |  2 +-
 pom.xml                                                        |  2 +-
 spark-gremlin/pom.xml                                          |  2 +-
 sparql-gremlin/pom.xml                                         |  2 +-
 tinkergraph-gremlin/pom.xml                                    |  2 +-
 38 files changed, 47 insertions(+), 37 deletions(-)


[tinkerpop] 01/01: TINKERPOP-2944 Dispose Cancellation callbacks

Posted by fl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

florianhockmann pushed a commit to branch TINKERPOP-2944
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit 27f7dbd96098013551fe63ea85c8e43c3e9ec467
Author: Florian Hockmann <fh...@florian-hockmann.de>
AuthorDate: Mon May 8 16:22:35 2023 +0200

    TINKERPOP-2944 Dispose Cancellation callbacks
    
    This should fix the memory leak described in TINKERPOP-2944 caused by
    not cleaning up the cancellation token registrations which contain
    a reference to the `RequestMessage`.
---
 CHANGELOG.asciidoc                                 |  2 +-
 .../src/Gremlin.Net/Driver/Connection.cs           | 32 ++++++++++++++--------
 2 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 0aff2937aa..cd68844925 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -23,7 +23,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 [[release-3-5-7]]
 === TinkerPop 3.5.7 (Release Date: NOT OFFICIALLY RELEASED YET)
 
-
+* Fixed a memory leak in the Gremlin.Net driver that only occurred if a CancellationToken was provided.
 
 [[release-3-5-6]]
 === TinkerPop 3.5.6 (Release Date: May 1, 2023)
diff --git a/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs b/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
index 223b979e28..407c9bf007 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs
@@ -50,14 +50,12 @@ namespace Gremlin.Net.Driver
         private readonly string _sessionId;
         private readonly bool _sessionEnabled;
 
-        private readonly ConcurrentQueue<(RequestMessage msg, CancellationToken cancellationToken)> _writeQueue =
-            new ConcurrentQueue<(RequestMessage, CancellationToken)>();
+        private readonly ConcurrentQueue<(RequestMessage msg, CancellationToken cancellationToken)> _writeQueue = new();
 
         private readonly ConcurrentDictionary<Guid, IResponseHandlerForSingleRequestMessage> _callbackByRequestId =
-            new ConcurrentDictionary<Guid, IResponseHandlerForSingleRequestMessage>();
-        
-        private readonly List<CancellationTokenRegistration> _cancellationTokenRegistrations =
-            new List<CancellationTokenRegistration>();
+            new();
+
+        private readonly ConcurrentDictionary<Guid, CancellationTokenRegistration> _cancellationByRequestId = new();
         private int _connectionState = 0;
         private int _writeInProgress = 0;
         private const int Closed = 1;
@@ -91,7 +89,8 @@ namespace Gremlin.Net.Driver
         {
             var receiver = new ResponseHandlerForSingleRequestMessage<T>();
             _callbackByRequestId.GetOrAdd(requestMessage.RequestId, receiver);
-            _cancellationTokenRegistrations.Add(cancellationToken.Register(() =>
+
+            _cancellationByRequestId.GetOrAdd(requestMessage.RequestId, cancellationToken.Register(() =>
             {
                 if (_callbackByRequestId.TryRemove(requestMessage.RequestId, out var responseHandler))
                 {
@@ -141,10 +140,11 @@ namespace Gremlin.Net.Driver
             }
             catch (Exception e)
             {
-                if (receivedMsg.RequestId != null &&
+                if (receivedMsg!.RequestId != null &&
                     _callbackByRequestId.TryRemove(receivedMsg.RequestId.Value, out var responseHandler))
                 {
                     responseHandler?.HandleFailure(e);
+                    _cancellationByRequestId.TryRemove(receivedMsg.RequestId.Value, out _);
                 }
             }
         }
@@ -175,6 +175,7 @@ namespace Gremlin.Net.Driver
             {
                 responseHandler?.Finalize(status.Attributes);
                 _callbackByRequestId.TryRemove(receivedMsg.RequestId.Value, out _);
+                _cancellationByRequestId.TryRemove(receivedMsg.RequestId.Value, out _);
             }
         }
 
@@ -256,6 +257,7 @@ namespace Gremlin.Net.Driver
                 cb.HandleFailure(exception);
             }
             _callbackByRequestId.Clear();
+            DisposeCancellationRegistrations();
         }
 
         private async Task SendMessageAsync(RequestMessage message, CancellationToken cancellationToken)
@@ -332,15 +334,21 @@ namespace Gremlin.Net.Driver
                 if (disposing)
                 {
                     _webSocketConnection?.Dispose();
-                    foreach (var registration in _cancellationTokenRegistrations)
-                    {
-                        registration.Dispose();
-                    }
+                    DisposeCancellationRegistrations();
                 }
                 _disposed = true;
             }
         }
 
+        private void DisposeCancellationRegistrations()
+        {
+            foreach (var cancellation in _cancellationByRequestId.Values)
+            {
+                cancellation.Dispose();
+            }
+            _cancellationByRequestId.Clear();
+        }
+
         #endregion
     }
 }
\ No newline at end of file