kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | f6a1bd2734a33f94f24dd1eb468ec7d71619ed2b621ff1707fb4ed007f1eafff |
|---|---|
| Author | Olivier Michallat <olim7t@users.noreply.github.com> · 2015-10-30 16:38 +01:00 |
| Committer | Olivier Michallat <olim7t@users.noreply.github.com> · 2015-10-30 16:38 +01:00 |
| Parents | 4a4ffe7ce8ed, 11a395190428 |
4 files changed
modified changelog/README.md +1 −0
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | - [bug] JAVA-954: Don't trigger reconnection before initialization complete. |
| 8 | 8 | - [improvement] JAVA-914: Avoid rejected tasks at shutdown. |
| 9 | 9 | - [improvement] JAVA-921: Add SimpleStatement.getValuesCount(). |
| 10 | +- [bug] JAVA-901: Move call to connection.release() out of cancelHandler. | |
| 10 | 11 | |
| 11 | 12 | |
| 12 | 13 | ### 2.0.11 |
modified driver-core/src/main/java/com/datastax/driver/core/Connection.java +3 −7
| @@ -452,10 +452,6 @@ | ||
| 452 | 452 | } catch (ExecutionException e) { |
| 453 | 453 | Throwable cause = e.getCause(); |
| 454 | 454 | if (cause instanceof OperationTimedOutException) { |
| 455 | - // The timeout logic released the connection, but that's wrong since we did not borrow it in the first place. | |
| 456 | - // JAVA-901 will fix this, in the meantime make sure the inFlight count is not off by one. | |
| 457 | - inFlight.incrementAndGet(); | |
| 458 | - | |
| 459 | 455 | // Rethrow so that the caller doesn't try to use the connection, but do not defunct as we don't want to mark down |
| 460 | 456 | logger.warn("Timeout while setting keyspace on connection to {}. " |
| 461 | 457 | + "This should not happen but is not critical (it will be retried)", address); |
| @@ -1227,16 +1223,16 @@ | ||
| 1227 | 1223 | timeout.cancel(); |
| 1228 | 1224 | } |
| 1229 | 1225 | |
| 1230 | - public void cancelHandler() { | |
| 1226 | + public boolean cancelHandler() { | |
| 1231 | 1227 | if (!isCancelled.compareAndSet(false, true)) |
| 1232 | - return; | |
| 1228 | + return false; | |
| 1233 | 1229 | |
| 1234 | 1230 | // We haven't really received a response: we want to remove the handle because we gave up on that |
| 1235 | 1231 | // request and there is no point in holding the handler, but we don't release the streamId. If we |
| 1236 | 1232 | // were, a new request could reuse that ID but get the answer to the request we just gave up on instead |
| 1237 | 1233 | // of its own answer, and we would have no way to detect that. |
| 1238 | 1234 | connection.dispatcher.removeHandler(this, false); |
| 1239 | - connection.release(); | |
| 1235 | + return true; | |
| 1240 | 1236 | } |
| 1241 | 1237 | |
| 1242 | 1238 | private TimerTask onTimeoutTask() { |
modified driver-core/src/main/java/com/datastax/driver/core/RequestHandler.java +7 −4
| @@ -352,8 +352,8 @@ | ||
| 352 | 352 | // If cancel() was called after we set the state to "in progress", but before connection.write had completed, it might have |
| 353 | 353 | // missed the new value of connectionHandler. So make sure that cancelHandler() gets called here (we might call it twice, |
| 354 | 354 | // but it knows how to deal with it). |
| 355 | - if (queryStateRef.get() == QueryState.CANCELLED_WHILE_IN_PROGRESS) | |
| 356 | - connectionHandler.cancelHandler(); | |
| 355 | + if (queryStateRef.get() == QueryState.CANCELLED_WHILE_IN_PROGRESS && connectionHandler.cancelHandler()) | |
| 356 | + connection.release(); | |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | private void retry(final boolean retryCurrent, ConsistencyLevel newConsistencyLevel) { |
| @@ -391,8 +391,8 @@ | ||
| 391 | 391 | logger.trace("[{}] Cancelled while in progress", id); |
| 392 | 392 | // The connectionHandler should be non-null, but we might miss the update if we're racing with write(). |
| 393 | 393 | // If it's still null, this will be handled by re-checking queryStateRef at the end of write(). |
| 394 | - if (connectionHandler != null) | |
| 395 | - connectionHandler.cancelHandler(); | |
| 394 | + if (connectionHandler != null && connectionHandler.cancelHandler()) | |
| 395 | + connectionHandler.connection.release(); | |
| 396 | 396 | return; |
| 397 | 397 | } else if (!previous.inProgress && queryStateRef.compareAndSet(previous, QueryState.CANCELLED_WHILE_COMPLETE)) { |
| 398 | 398 | if(logger.isTraceEnabled()) |
| @@ -671,6 +671,7 @@ | ||
| 671 | 671 | retryCount, queryState, queryStateRef.get()); |
| 672 | 672 | return false; |
| 673 | 673 | } |
| 674 | + connection.release(); | |
| 674 | 675 | logError(connection.address, new DriverException("Timeout waiting for response to prepare message")); |
| 675 | 676 | retry(false, null); |
| 676 | 677 | return true; |
| @@ -723,6 +724,8 @@ | ||
| 723 | 724 | Host queriedHost = current; |
| 724 | 725 | OperationTimedOutException timeoutException = new OperationTimedOutException(connection.address); |
| 725 | 726 | try { |
| 727 | + connection.release(); | |
| 728 | + | |
| 726 | 729 | logError(connection.address, timeoutException); |
| 727 | 730 | retry(false, null); |
| 728 | 731 | } catch (Exception e) { |
modified driver-core/src/main/java/com/datastax/driver/core/SessionManager.java +1 −4
| @@ -583,10 +583,7 @@ | ||
| 583 | 583 | @Override |
| 584 | 584 | public void onFailure(Throwable t) { |
| 585 | 585 | logger.debug(String.format("Unexpected error while preparing query (%s) on %s", query, entry.getKey()), t); |
| 586 | - | |
| 587 | - // If the query timed out, that already released the connection, otherwise do it now | |
| 588 | - if (!(t instanceof OperationTimedOutException)) | |
| 589 | - c.release(); | |
| 586 | + c.release(); | |
| 590 | 587 | } |
| 591 | 588 | }); |
| 592 | 589 | futures.add(future); |