Skip to content

Commit

Permalink
Fix a race between VBP_Remove() and vbp_thread()
Browse files Browse the repository at this point in the history
Suppose the following happens:

vbp_task() finishes with vt->running = 0 and a heap insert. The
vbp_cond is signaled under the lock, but now instead of vbp_thread()
waking up first, VBP_Remove() gets the lock and reaches
assert(vt->heap_idx == VBH_NOIDX) before the racing vbp_thread()
deleted the heap.

This is unlikely to happen with static backends, because for those,
the probe is stopped via the vcl temperature before they get removed.

Fixes nigoroll/libvmod-dynamic#100
  • Loading branch information
nigoroll authored and dridi committed Oct 25, 2023
1 parent aacf777 commit 1fb4303
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bin/varnishd/cache/cache_backend_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,12 @@ VBP_Remove(struct backend *be)
be->probe = NULL;
vt->backend = NULL;
if (vt->running) {
// task scheduled, it calls vbp_delete()
vt->running = -1;
vt = NULL;
} else if (vt->heap_idx != VBH_NOIDX) {
// task done, not yet rescheduled
VBH_delete(vbp_heap, vt->heap_idx);
}
Lck_Unlock(&vbp_mtx);
if (vt != NULL) {
Expand Down

0 comments on commit 1fb4303

Please sign in to comment.