Commit 32af38d4 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp Committed by Lasse Karstensen

Add a final backstop, so we absolutely 100% certainly do not

try to delete a objhead while it still has a waiting list,
by forcing the last ref holder to rush the WL.

Since the hasher owns the refcounts on objhead, we cannot just
mingle req and objcore refcounts.

Fortunately we don't need to add another refcounter, because all
we really care about is the wl being empty when we drop the last
ref.

The wl/hsh_rush() mechanism will work differently with different
thread-scheduling schenarios, and I cannot definitively rule out
that we can drop the last ref on an oh, while there are still req's
on the waiting list.

Given that, and the existence proof in ticket #1823's race, this
might have been the indicated memory-trampler.

Conflicts:
	bin/varnishd/cache/cache_hash.c
parent c17c701b
......@@ -820,10 +820,25 @@ HSH_DerefObjHead(struct worker *wrk, struct objhead **poh)
oh->refcnt--;
Lck_Unlock(&oh->mtx);
return(1);
} else if (oh->waitinglist != NULL) {
}
/*
* Make absolutely certain that we do not let the final ref
* disappear until the waitinglist is empty.
* This is necessary because the req's on the waiting list do
* not hold any ref on the objhead of their own, and we cannot
* just make the hold the same ref's as objcore, that would
* confuse hashers.
*/
while (oh->waitinglist != NULL) {
Lck_Lock(&oh->mtx);
assert(oh->refcnt > 0);
r = oh->refcnt;
hsh_rush(wrk, oh);
Lck_Unlock(&oh->mtx);
if (r > 1)
break;
usleep(100000);
}
assert(oh->refcnt > 0);
......
......@@ -394,9 +394,7 @@ hcb_start(void)
static int __match_proto__(hash_deref_f)
hcb_deref(struct objhead *oh)
{
int r;
r = 1;
CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
Lck_Lock(&oh->mtx);
assert(oh->refcnt > 0);
......@@ -413,7 +411,7 @@ hcb_deref(struct objhead *oh)
#ifdef PHK
fprintf(stderr, "hcb_defef %d %d <%s>\n", __LINE__, r, oh->hash);
#endif
return (r);
return (1);
}
static struct objhead * __match_proto__(hash_lookup_f)
......
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