jolestar / go-commons-pool

a generic object pool for golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

With multiple waiting calls to BorrowObject, some will block forever if PassivateObject returns an error

dcormier opened this issue · comments

In some conditions, BorrowObject will block forever even if all previous callers returned their objects to the pool.

Steps to reproduce:

  1. Configure that pool with a maximum limit of 1 (set MaxTotal = 1)
  2. Borrow the item from the pool
  3. Make two additional calls to BorrowObject
  4. Return the borrowed item (from step 2) to the pool, causing PassivateObject to return an error
  5. One of the additional calls to BorrowObject should have now gotten an object. Return it, causing PassivateObject to fail again.

At this point, the third call to BorrowObject will be blocked, even though the two prior calls to BorrowObject both called ReturnObject.

I have added a failing test showing this, here.

I'm looking into fixing this.