kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 0a81df13374780192fdeed1f30aee901a7e32bc77a43857c8ef9914733ec8fe3 |
|---|---|
| Author | Olivier Michallat <olim7t@users.noreply.github.com> · 2015-10-30 16:40 +01:00 |
| Committer | Olivier Michallat <olim7t@users.noreply.github.com> · 2015-10-30 16:40 +01:00 |
| Parents | f6a1bd2734a3, 83eca905ea7c |
2 files changed
modified changelog/README.md +1 −0
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | - [improvement] JAVA-914: Avoid rejected tasks at shutdown. |
| 9 | 9 | - [improvement] JAVA-921: Add SimpleStatement.getValuesCount(). |
| 10 | 10 | - [bug] JAVA-901: Move call to connection.release() out of cancelHandler. |
| 11 | +- [bug] JAVA-960: Avoid race in control connection shutdown. | |
| 11 | 12 | |
| 12 | 13 | |
| 13 | 14 | ### 2.0.11 |
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +14 −0
| @@ -123,6 +123,9 @@ | ||
| 123 | 123 | new AbstractReconnectionHandler("Control connection", cluster.reconnectionExecutor, cluster.reconnectionPolicy().newSchedule(), reconnectionAttempt, initialDelayMs) { |
| 124 | 124 | @Override |
| 125 | 125 | protected Connection tryReconnect() throws ConnectionException { |
| 126 | + if (isShutdown) | |
| 127 | + throw new ConnectionException(null, "Control connection was shut down"); | |
| 128 | + | |
| 126 | 129 | try { |
| 127 | 130 | return reconnectInternal(queryPlan(), false); |
| 128 | 131 | } catch (NoHostAvailableException e) { |
| @@ -136,17 +139,28 @@ | ||
| 136 | 139 | |
| 137 | 140 | @Override |
| 138 | 141 | protected void onReconnection(Connection connection) { |
| 142 | + if (isShutdown) { | |
| 143 | + connection.closeAsync(); | |
| 144 | + return; | |
| 145 | + } | |
| 146 | + | |
| 139 | 147 | setNewConnection(connection); |
| 140 | 148 | } |
| 141 | 149 | |
| 142 | 150 | @Override |
| 143 | 151 | protected boolean onConnectionException(ConnectionException e, long nextDelayMs) { |
| 152 | + if (isShutdown) | |
| 153 | + return false; | |
| 154 | + | |
| 144 | 155 | logger.error("[Control connection] Cannot connect to any host, scheduling retry in {} milliseconds", nextDelayMs); |
| 145 | 156 | return true; |
| 146 | 157 | } |
| 147 | 158 | |
| 148 | 159 | @Override |
| 149 | 160 | protected boolean onUnknownException(Exception e, long nextDelayMs) { |
| 161 | + if (isShutdown) | |
| 162 | + return false; | |
| 163 | + | |
| 150 | 164 | logger.error(String.format("[Control connection] Unknown error during reconnection, scheduling retry in %d milliseconds", nextDelayMs), e); |
| 151 | 165 | return true; |
| 152 | 166 | } |