[4.0] b135934 Fix a race when we Unbusy and abandonned oc which has no object.
Poul-Henning Kamp
phk at FreeBSD.org
Tue Apr 1 15:09:48 CEST 2014
commit b135934f9eace9bc281b3e727f37dfd302170fa8
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Fri Mar 14 09:24:41 2014 +0000
Fix a race when we Unbusy and abandonned oc which has no object.
Fixes #1449
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index e0c9350..b5cb463 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -682,10 +682,9 @@ vbf_stp_fail(struct worker *wrk, struct busyobj *bo)
CHECK_OBJ_NOTNULL(bo->fetch_objcore, OBJCORE_MAGIC);
assert(bo->state < BOS_FINISHED);
- bo->fetch_objcore->flags |= OC_F_PRIVATE;
+ HSH_Fail(bo->fetch_objcore);
if (bo->fetch_objcore->flags & OC_F_BUSY)
HSH_Unbusy(&wrk->stats, bo->fetch_objcore);
- HSH_Fail(bo->fetch_objcore);
wrk->stats.fetch_failed++;
VBO_setstate(bo, BOS_FAILED);
return (F_STP_DONE);
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 882c84b..dbcfaee 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -629,6 +629,13 @@ HSH_Fail(struct objcore *oc)
oh = oc->objhead;
CHECK_OBJ(oh, OBJHEAD_MAGIC);
+ /*
+ * We have to have either a busy bit, so that HSH_Lookup
+ * will not consider this oc, or an object hung of the oc
+ * so that it can consider it.
+ */
+ assert((oc->flags & OC_F_BUSY) || (oc->methods != NULL));
+
Lck_Lock(&oh->mtx);
oc->flags |= OC_F_FAILED;
Lck_Unlock(&oh->mtx);
@@ -678,7 +685,7 @@ HSH_Unbusy(struct dstat *ds, struct objcore *oc)
if (oh->waitinglist != NULL)
hsh_rush(ds, oh);
Lck_Unlock(&oh->mtx);
- if (!(oc->flags & OC_F_PRIVATE)) {
+ if (!(oc->flags & OC_F_PRIVATE) && oc->methods != NULL) {
BAN_NewObjCore(oc);
EXP_Insert(oc);
AN(oc->flags & OC_F_EXP);
More information about the varnish-commit
mailing list