浏览代码

use ConnectTimeout for options message (#1217)

Jaume Marhuenda 7 年之前
父节点
当前提交
f0078a2a19
共有 2 个文件被更改,包括 4 次插入2 次删除
  1. 3 1
      conn.go
  2. 1 1
      conn_test.go

+ 3 - 1
conn.go

@@ -199,7 +199,6 @@ func (s *Session) dial(host *HostInfo, cfg *ConnConfig, errorHandler ConnErrorHa
 		r:             bufio.NewReader(conn),
 		cfg:           cfg,
 		calls:         make(map[int]*callReq),
-		timeout:       cfg.Timeout,
 		version:       uint8(cfg.ProtoVersion),
 		addr:          conn.RemoteAddr().String(),
 		errorHandler:  errorHandler,
@@ -232,11 +231,14 @@ func (s *Session) dial(host *HostInfo, cfg *ConnConfig, errorHandler ConnErrorHa
 		conn:        c,
 	}
 
+	c.timeout = cfg.ConnectTimeout
 	if err := startup.setupConn(ctx); err != nil {
 		c.close()
 		return nil, err
 	}
 
+	c.timeout = cfg.Timeout
+
 	// dont coalesce startup frames
 	if s.cfg.WriteCoalesceWaitTime > 0 {
 		c.w = newWriteCoalescer(c.w, s.cfg.WriteCoalesceWaitTime, c.quit)

+ 1 - 1
conn_test.go

@@ -658,7 +658,7 @@ func TestQueryTimeout(t *testing.T) {
 		if err != ErrTimeoutNoResponse {
 			t.Fatalf("expected to get %v for timeout got %v", ErrTimeoutNoResponse, err)
 		}
-	case <-time.After(10*time.Millisecond + db.cfg.Timeout):
+	case <-time.After(40*time.Millisecond + db.cfg.Timeout):
 		// ensure that the query goroutines have been scheduled
 		t.Fatalf("query did not timeout after %v", db.cfg.Timeout)
 	}