Race between IsExpired() and Delete()
Introduced in !25 (merged), we replace a single call to Free()
which checked expiration logic and performed a deletion within the same lock hold, with:
if instance.IsExpired(time.Duration(active.IdleTime)) {
instance.Remove()
n++
}
IsExpired()
and Remove()
both acquire a lock, but this makes it possible for a call to Acquire()
to grab the lock in between the check and deletion and assign a job only to have the instance then removed. Calls to Acquire()
are done in a tight loop often as check for possible job slots, and I believe start with the oldest instances first (most likely to be expiring).
IsExpired
is only used in this one place, so I think we can update it to be called RemoveIfExpired()
and it handle both the expiration logic and deletion in one call/lock.
Edited by Arran Walker