Elffuss BraidHub

kikocis/java-driver public

Fix issue when newly opened pool fails before we could mark the node UP (JAVA-642).
Changeset00adccdfeee8432f8ff740440a3798eda3f1df9d729a9e39d17cd413c5415854
Authorolim7t <omichallat+github@gmail.com> · 2015-01-29 23:27 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2015-01-30 15:41 +01:00
Parentsee4de8e6237f

Browse the files at this changeset

3 files changed

modified driver-core/CHANGELOG.rst +2 −0
@@ -7,6 +7,8 @@
77 - [bug] Prevent race between cancellation and query completion (JAVA-614)
88 - [bug] Prevent cancel and timeout from cancelling unrelated ResponseHandler if
99 streamId was already released and reused (JAVA-632).
10+- [bug] Fix issue when newly opened pool fails before we could mark the node UP
11+ (JAVA-642)
1012
1113
1214 2.0.9:
modified driver-core/src/main/java/com/datastax/driver/core/Connection.java +11 −1
@@ -276,9 +276,19 @@
276276 // sure the "suspected" mechanism work as expected
277277 Host host = factory.manager.metadata.getHost(address);
278278 if (host != null) {
279+
280+ // If the host was reconnecting, and this error happens right after we opened a connection pool, but
281+ // before we could mark the node UP, we don't want to go through the SUSPECTED state, because that can
282+ // lead to a race condition that leaves the node UP with a closed pool.
283+ boolean belongsToReconnectingPool = host.state != Host.State.UP &&
284+ this instanceof PooledConnection &&
285+ (((PooledConnection)this).pool == null || !((PooledConnection)this).pool.isClosed());
286+
287+ boolean markSuspected = isInitialized && !belongsToReconnectingPool;
288+
279289 // This will trigger onDown, including when the defunct Connection is part of a reconnection attempt, which is redundant.
280290 // This is not too much of a problem since calling onDown on a node that is already down has no effect.
281- boolean isDown = factory.manager.signalConnectionFailure(host, ce, host.wasJustAdded(), isInitialized);
291+ boolean isDown = factory.manager.signalConnectionFailure(host, ce, host.wasJustAdded(), markSuspected);
282292 notifyOwnerWhenDefunct(isDown);
283293 }
284294
modified driver-core/src/main/java/com/datastax/driver/core/PooledConnection.java +1 −1
@@ -23,7 +23,7 @@
2323 */
2424 class PooledConnection extends Connection {
2525
26- private final HostConnectionPool pool;
26+ final HostConnectionPool pool;
2727
2828 /** Used in {@link HostConnectionPool} to handle races between two threads trying to trash the same connection */
2929 final AtomicBoolean markForTrash = new AtomicBoolean();