Skip to content

Commit

Permalink
Fixing connection cleanup in case of mass connection breaking.
Browse files Browse the repository at this point in the history
 CAUSE:
 In some cases when credentials expire, or servers encounters a
 blip and closes all connections. The driver gets close message on all
 connections. While processing those close messages, the driver was
 getting into race conditions, where in multiple threads were trying to
 close connections and trying to update the connections object i.e. list
 of connections in the pool. This was leading to uncaught exceptions and
 stale connections in the pool. These connections are never cleanedup
 post this.

 FIX:
 Iterate the connections list while creating the connectionPool Info.
 Since the list used is copyOnWrite, the iterator API creates a clone
 and uses that clone for referring the element. Thus providing thread
 safe interface.

 However the information provided by this iteration is a bit stale, but
 this doesn't matter.
  • Loading branch information
upadhyay-prashant committed May 21, 2024
1 parent 7369fba commit 424406f
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.tinkerpop.gremlin.util.TimeUtil;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -663,18 +664,19 @@ public String getPoolInfo(final Connection connectionToCallout) {

private void appendConnections(final StringBuilder sb, final Connection connectionToCallout,
final List<Connection> connections) {
final int connectionCount = connections.size();
for (int ix = 0; ix < connectionCount; ix++) {
final Connection c = connections.get(ix);
if (c.equals(connectionToCallout))
final Iterator<Connection> it = connections.iterator();
while(it.hasNext()) {
final Connection c = it.next();
if (c.equals(connectionToCallout)) {
sb.append("==> ");
else
}
else {
sb.append("> ");

}
sb.append(c.getConnectionInfo(false));

if (ix < connectionCount - 1)
if (it.hasNext()) {
sb.append(System.lineSeparator());
}
}
}

Expand Down

0 comments on commit 424406f

Please sign in to comment.