Permalink
Browse files

Merge pull request #556 from thobbs/fix-ssl-double-socket-open

Avoid trying to open the socket twice when using SSL
  • Loading branch information...
2 parents 3c6d005 + 861b1bd commit d7653555cb92cb0957057b9cd26e1a1f9c7c2d73 @zznate zznate committed Nov 10, 2012
Showing with 14 additions and 9 deletions.
  1. +14 −9 core/src/main/java/me/prettyprint/cassandra/connection/client/HThriftClient.java
@@ -166,15 +166,20 @@ public HThriftClient open() {
transport = socket;
}
- try {
- transport.open();
- } catch (TTransportException e) {
- // Thrift exceptions aren't very good in reporting, so we have to catch the exception here and
- // add details to it.
- log.debug("Unable to open transport to " + cassandraHost.getName());
- //clientMonitor.incCounter(Counter.CONNECT_ERROR);
- throw new HectorTransportException("Unable to open transport to " + cassandraHost.getName() +" , " +
- e.getLocalizedMessage(), e);
+ // If using SSL, the socket will already be connected, and TFramedTransport and
+ // TSocket just wind up calling socket.isConnected(), so check this before calling
+ // open() to avoid a "Socket already connected" error.
+ if (!transport.isOpen()) {
+ try {
+ transport.open();
+ } catch (TTransportException e) {
+ // Thrift exceptions aren't very good in reporting, so we have to catch the exception here and
+ // add details to it.
+ log.debug("Unable to open transport to " + cassandraHost.getName());
+ //clientMonitor.incCounter(Counter.CONNECT_ERROR);
+ throw new HectorTransportException("Unable to open transport to " + cassandraHost.getName() +" , " +
+ e.getLocalizedMessage(), e);
+ }
}
return this;
}

0 comments on commit d765355

Please sign in to comment.