Skip to content

Commit

Permalink
Pool: notify fewer waiters on returned connection (#559)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephen Cathcart <stephen.cathcart@neotechnology.com>
  • Loading branch information
robsdedude and StephenCathcart authored Dec 14, 2023
1 parent 042c154 commit fdbce9f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion neo4j/internal/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,17 @@ func (p *Pool) Borrow(
case <-ctx.Done():
p.queueMut.Lock()
p.queue.Remove(e)
if len(q.wakeup) == 1 {
// We got notified, but are no longer interested.
// Ask the next waiter.
if e := p.queue.Front(); e != nil {
queuedRequest := e.Value.(*qitem)
p.queue.Remove(e)
queuedRequest.wakeup <- true
}
p.queueMut.Unlock()
continue
}
p.queueMut.Unlock()
p.log.Warnf(log.Pool, p.logId, "Borrow time-out")
return nil, &errorutil.PoolTimeout{Err: ctx.Err(), Servers: serverNames}
Expand Down Expand Up @@ -425,7 +436,8 @@ func (p *Pool) Return(ctx context.Context, c idb.Connection) {

// Check if there is anyone in the queue waiting for a connection to this server.
p.queueMut.Lock()
for e := p.queue.Front(); e != nil; e = e.Next() {

if e := p.queue.Front(); e != nil {
queuedRequest := e.Value.(*qitem)
p.queue.Remove(e)
queuedRequest.wakeup <- true
Expand Down

0 comments on commit fdbce9f

Please sign in to comment.