Elffuss BraidHub

kikocis/java-driver public

Merge pull request #509 from datastax/java960

JAVA-960: Avoid race in control connection shutdown.
Changeset0a81df13374780192fdeed1f30aee901a7e32bc77a43857c8ef9914733ec8fe3
AuthorOlivier Michallat <olim7t@users.noreply.github.com> · 2015-10-30 16:40 +01:00
CommitterOlivier Michallat <olim7t@users.noreply.github.com> · 2015-10-30 16:40 +01:00
Parentsf6a1bd2734a3, 83eca905ea7c

Browse the files at this changeset

2 files changed

modified changelog/README.md +1 −0
@@ -8,6 +8,7 @@
88 - [improvement] JAVA-914: Avoid rejected tasks at shutdown.
99 - [improvement] JAVA-921: Add SimpleStatement.getValuesCount().
1010 - [bug] JAVA-901: Move call to connection.release() out of cancelHandler.
11+- [bug] JAVA-960: Avoid race in control connection shutdown.
1112
1213
1314 ### 2.0.11
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +14 −0
@@ -123,6 +123,9 @@
123123 new AbstractReconnectionHandler("Control connection", cluster.reconnectionExecutor, cluster.reconnectionPolicy().newSchedule(), reconnectionAttempt, initialDelayMs) {
124124 @Override
125125 protected Connection tryReconnect() throws ConnectionException {
126+ if (isShutdown)
127+ throw new ConnectionException(null, "Control connection was shut down");
128+
126129 try {
127130 return reconnectInternal(queryPlan(), false);
128131 } catch (NoHostAvailableException e) {
@@ -136,17 +139,28 @@
136139
137140 @Override
138141 protected void onReconnection(Connection connection) {
142+ if (isShutdown) {
143+ connection.closeAsync();
144+ return;
145+ }
146+
139147 setNewConnection(connection);
140148 }
141149
142150 @Override
143151 protected boolean onConnectionException(ConnectionException e, long nextDelayMs) {
152+ if (isShutdown)
153+ return false;
154+
144155 logger.error("[Control connection] Cannot connect to any host, scheduling retry in {} milliseconds", nextDelayMs);
145156 return true;
146157 }
147158
148159 @Override
149160 protected boolean onUnknownException(Exception e, long nextDelayMs) {
161+ if (isShutdown)
162+ return false;
163+
150164 logger.error(String.format("[Control connection] Unknown error during reconnection, scheduling retry in %d milliseconds", nextDelayMs), e);
151165 return true;
152166 }