浏览代码

Stop retrying to connect on permanent failure

Minor change to the connection pool code that uses the *net.OpError type
to pull of retrying to connect to a host if the error is a permanent
erorr.

Reduces startup time on creating a new sesession when we try to
establish a connection using gocql that does not have visibility to the
host.

Performance improvement easily reproduced when using default cassandra
docker container with gocql.
Michael Highstead 10 年之前
父节点
当前提交
6e5ecf85b5
共有 2 个文件被更改,包括 8 次插入0 次删除
  1. 1 0
      AUTHORS
  2. 7 0
      connectionpool.go

+ 1 - 0
AUTHORS

@@ -69,3 +69,4 @@ Alexander Inozemtsev <alexander.inozemtsev@gmail.com>
 Rob McColl <rob@robmccoll.com>; <rmccoll@ionicsecurity.com>
 Viktor Tönköl <viktor.toenkoel@motionlogic.de>
 Ian Lozinski <ian.lozinski@gmail.com>
+Michael Highstead <highstead@gmail.com>

+ 7 - 0
connectionpool.go

@@ -481,6 +481,13 @@ func (pool *hostConnPool) connect() (err error) {
 		if err == nil {
 			break
 		}
+		if opErr, isOpErr := err.(*net.OpError); isOpErr {
+			// if the error is not a temporary error (ex: network unreachable) don't
+			//  retry
+			if !opErr.Temporary() {
+				break
+			}
+		}
 	}
 
 	if err != nil {