Browse Source

Resolved issue of connections reconnecting in an infinite loop consuming
all available ports.

Updated the gocql_test to pause for 15 seconds to test that this issue
doesn't recur in future releases.

Phillip Couto 12 years ago
parent
commit
c0c4dafb44
2 changed files with 7 additions and 2 deletions
  1. 4 2
      cluster.go
  2. 3 0
      gocql_test/main.go

+ 4 - 2
cluster.go

@@ -59,7 +59,7 @@ func (cfg *ClusterConfig) CreateSession() *Session {
 		connPool: make(map[string]*RoundRobin),
 		conns:    make(map[*Conn]struct{}),
 		quitWait: make(chan bool),
-		keyspace: cfg.Keyspace,		
+		keyspace: cfg.Keyspace,
 	}
 	impl.wgStart.Add(1)
 	for i := 0; i < len(impl.cfg.Hosts); i++ {
@@ -179,7 +179,9 @@ func (c *clusterImpl) HandleError(conn *Conn, err error, closed bool) {
 		return
 	}
 	c.removeConn(conn)
-	go c.connect(conn.Address()) // reconnect
+	if !c.quit {
+		go c.connect(conn.Address()) // reconnect
+	}
 }
 
 func (c *clusterImpl) HandleKeyspace(conn *Conn, keyspace string) {

+ 3 - 0
gocql_test/main.go

@@ -51,7 +51,10 @@ func initSchema() error {
 		}`).Exec(); err != nil {
 		return err
 	}
+	log.Println("Testing that the connections do not reconnect in an infinite loop.")
 	session.Close()
+	time.Sleep(15 * time.Second)
+	log.Println("If there were error messages that an address cannot be assigned then the test failed.")
 	cluster.Keyspace = "gocql_test"
 	session = cluster.CreateSession()