Elffuss BraidHub

kikocis/java-driver public

Fix race when multiple connect are done in parallel

JAVA-261 #fixes
Changeset0df8e9f3e4b8f1f5fa98a0fe180829474ecb1b4a9a205ce4e2056c8227bd6b9f
AuthorSylvain Lebresne <sylvain@datastax.com> · 2014-02-25 15:06 +01:00
CommitterSylvain Lebresne <sylvain@datastax.com> · 2014-02-25 15:06 +01:00
Parents80afbe6294e6

Browse the files at this changeset

2 files changed

modified driver-core/CHANGELOG.rst +1 −0
@@ -13,6 +13,7 @@
1313 - [bug] Make sure connections are returned to the right pools (JAVA-255)
1414 - [bug] Use date string in query build to work-around CASSANDRA-6718 (JAVA-264)
1515 - [bug] Always return the PreparedStatement object that is cache internally (JAVA-263)
16+- [bug] Fix race when multiple connect are done in parallel (JAVA-261)
1617
1718
1819 1.0.5:
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +7 −3
@@ -735,7 +735,7 @@
735735 */
736736 class Manager implements Host.StateListener, Connection.DefaultResponseHandler {
737737
738- private final AtomicBoolean isInit = new AtomicBoolean(false);
738+ private boolean isInit;
739739
740740 // Initial contacts point
741741 final List<InetAddress> contactPoints;
@@ -789,8 +789,10 @@
789789 this.configuration.register(this);
790790 }
791791
792- private void init() {
793- if (!isInit.compareAndSet(false, true))
792+ // Initialization is not too performance intensive and in practice there shouldn't be contention
793+ // on it so synchronized is good enough.
794+ private synchronized void init() {
795+ if (isInit)
794796 return;
795797
796798 // Note: we mark the initial contact point as UP, because we have no prior
@@ -815,6 +817,8 @@
815817 }
816818 throw e;
817819 }
820+
821+ isInit = true;
818822 }
819823
820824 Cluster getCluster() {