Cached cat-file processes may be "dirtied" after they have been put back into the cache
We currently use the following logic to return used git cat-file --batch processes into the global cache:
// c is a catfile instance
<- ctx.Done()
if isDirty(c) {
// dirty c cannot be reused
return
}
cache.Add(c)
The problem is that another goroutine may still be holding c, and may dirty it after our if isDirty(c) check. This will then cause an "undeserved" error for the next request that uses c.
As a solution I propose:
- rename
BatchtobatchCore, and only cachebatchCore - create new
type Batch structwhich contains*batchCorefield - every consumer gets a fresh
*Batchinstance - add field
token inttobatchCoreandBatch - at checkout,
c.token = c.batchCore.token - all methods on
*Batchstart by checking ifc.token == c.batchCore.token - at checkin, before we do the
isDirtycheck, incrementc.batchCore.token
This way we can cut off old consumers from using a *batchCore we are returning to the cache.
Edited by Jacob Vosmaer