[master] b825f55f3 vrt_vcl: Avoid retirement of assigned director
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Tue Dec 10 17:54:11 UTC 2024
commit b825f55f348595cfc24f5eee92b86ecf2e880924
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Mon Dec 9 18:43:01 2024 +0100
vrt_vcl: Avoid retirement of assigned director
Consider the following VCL statement:
set bereq.backend = bereq.backend;
The director's refcount will be decremented before it is incremented. If
that bereq.backend was holding the last reference of a dynamic backend,
the backend is retired before acquiring a new reference.
While this scenario is highly unlikely, we cannot discard the risk of
assigning a director to a destination that already held a reference to
the same director.
diff --git a/bin/varnishd/cache/cache_vrt_vcl.c b/bin/varnishd/cache/cache_vrt_vcl.c
index 82e6e10a5..33ba68241 100644
--- a/bin/varnishd/cache/cache_vrt_vcl.c
+++ b/bin/varnishd/cache/cache_vrt_vcl.c
@@ -336,6 +336,8 @@ VRT_Assign_Backend(VCL_BACKEND *dst, VCL_BACKEND src)
AN(dst);
CHECK_OBJ_ORNULL((*dst), DIRECTOR_MAGIC);
CHECK_OBJ_ORNULL(src, DIRECTOR_MAGIC);
+ if (*dst == src)
+ return;
if (*dst != NULL) {
vdir = (*dst)->vdir;
CHECK_OBJ_NOTNULL(vdir, VCLDIR_MAGIC);
More information about the varnish-commit
mailing list