Skip to content

Commit

Permalink
fix: goroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroyky committed Nov 17, 2023
1 parent 4d5aeac commit 5369eaa
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions memcache/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ func (p *pool) getConn() (*conn, error) {
}

// return latest freeconn or wait until to become free
return <-p.freeconns, nil
cn = <-p.freeconns
return cn, nil
}

func (p *pool) isNewConnOk() bool {
Expand All @@ -102,13 +103,15 @@ func (p *pool) isNewConnOk() bool {
}

func (p *pool) putFreeConn(cn *conn) {
p.lk.Lock()
defer p.lk.Unlock()
if p.freeconns == nil {
p.freeconns = make(chan *conn)
}
p.freeconns <- cn
p.freeconnsNum++
go func() {
p.lk.Lock()
defer p.lk.Unlock()
if p.freeconns == nil {
p.freeconns = make(chan *conn)
}
p.freeconns <- cn
p.freeconnsNum++
}()
}

func (p *pool) closeConn(cn *conn) {
Expand Down

0 comments on commit 5369eaa

Please sign in to comment.