Skip to content

Commit

Permalink
conn: dont mutate the conn config
Browse files Browse the repository at this point in the history
The conn config is shared by the connection pool.

Updates apache#519
  • Loading branch information
Zariel committed Nov 2, 2015
1 parent 5ea083a commit 75ef4c2
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,19 @@ func Connect(addr string, cfg *ConnConfig, errorHandler ConnErrorHandler, sessio
headerSize = 9
}

if cfg.NumStreams <= 0 || cfg.NumStreams >= maxStreams {
cfg.NumStreams = maxStreams
streams := cfg.NumStreams
if streams <= 0 || streams >= maxStreams {
streams = maxStreams
} else {
cfg.NumStreams++
streams++
}

c := &Conn{
conn: conn,
r: bufio.NewReader(conn),
cfg: cfg,
uniq: make(chan int, cfg.NumStreams),
calls: make([]callReq, cfg.NumStreams),
uniq: make(chan int, streams),
calls: make([]callReq, streams),
timeout: cfg.Timeout,
version: uint8(cfg.ProtoVersion),
addr: conn.RemoteAddr().String(),
Expand All @@ -189,7 +190,7 @@ func Connect(addr string, cfg *ConnConfig, errorHandler ConnErrorHandler, sessio

// reserve stream 0 incase cassandra returns an error on it without us sending
// a request.
for i := 1; i < cfg.NumStreams; i++ {
for i := 1; i < streams; i++ {
c.calls[i].resp = make(chan error)
c.uniq <- i
}
Expand Down

0 comments on commit 75ef4c2

Please sign in to comment.