Do not mutate dying objects

Avoid memory LRU racing disk LRU.

Disk LRU uses the varnish-cache LRU facility, which works by setting
the OC_F_DYING and gaining one reference, resulting in two references.

One is lost again by the thread initiating the LRU nuke, the other by
the EXP thread. Between the two events, the refcnt is one again, thus
stvfe_mutate could race.

I believe this fixes #23 and #24. If not, please reopen
parent 712d7edb
......@@ -1780,8 +1780,10 @@ stvfe_mutate(struct worker *wrk, struct fellow_cache_lru *lru,
oh = oc->objhead;
CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
if (oc->refcnt == 1 && !Lck_Trylock(&oh->mtx)) {
if (oc->refcnt != 1)
if (oc->refcnt == 1 &&
!(oc->flags & OC_F_DYING) &&
!Lck_Trylock(&oh->mtx)) {
if (oc->refcnt != 1 || (oc->flags & OC_F_DYING))
goto unlock;
stv = oc_stv(wrk, oc);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment