kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 5816920af92f1424598ac02ab2892cd30baa77d7daf55e741014f2792ec6ef95 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2014-12-07 12:07 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-12-09 18:30 +01:00 |
| Parents | 6068c037a5f5 |
2 files changed
modified driver-core/CHANGELOG.rst +2 −0
| @@ -9,6 +9,8 @@ | ||
| 9 | 9 | - [bug] Don't check rpc_address for control host (JAVA-546) |
| 10 | 10 | - [improvement] Improve message of NoHostAvailableException (JAVA-409) |
| 11 | 11 | - [bug] Rework connection reaper to avoid deadlock (JAVA-556) |
| 12 | +- [bug] Avoid deadlock when multiple connections to the same host get write | |
| 13 | + errors (JAVA-557) | |
| 12 | 14 | |
| 13 | 15 | |
| 14 | 16 | 2.0.8: |
modified driver-core/src/main/java/com/datastax/driver/core/Connection.java +13 −2
| @@ -380,13 +380,24 @@ | ||
| 380 | 380 | // twice (we will fail that method already) |
| 381 | 381 | dispatcher.removeHandler(handler.streamId, true); |
| 382 | 382 | |
| 383 | - ConnectionException ce; | |
| 383 | + final ConnectionException ce; | |
| 384 | 384 | if (writeFuture.getCause() instanceof java.nio.channels.ClosedChannelException) { |
| 385 | 385 | ce = new TransportException(address, "Error writing: Closed channel"); |
| 386 | 386 | } else { |
| 387 | 387 | ce = new TransportException(address, "Error writing", writeFuture.getCause()); |
| 388 | 388 | } |
| 389 | - handler.callback.onException(Connection.this, defunct(ce), System.nanoTime() - handler.startTime, handler.retryCount); | |
| 389 | + final long latency = System.nanoTime() - handler.startTime; | |
| 390 | + // This handler is executed while holding the writeLock of the channel. | |
| 391 | + // defunct might close the pool, which will close all of its connections; closing a connection also | |
| 392 | + // requires its writeLock. | |
| 393 | + // Therefore if multiple connections in the same pool get a write error, they could deadlock; | |
| 394 | + // we run defunct on a separate thread to avoid that. | |
| 395 | + factory.manager.executor.execute(new Runnable() { | |
| 396 | + @Override | |
| 397 | + public void run() { | |
| 398 | + handler.callback.onException(Connection.this, defunct(ce), latency, handler.retryCount); | |
| 399 | + } | |
| 400 | + }); | |
| 390 | 401 | } else { |
| 391 | 402 | logger.trace("{} request sent successfully", Connection.this); |
| 392 | 403 | } |