[master] 90c5be03d shard: add error message for invalid weight

Nils Goroll nils.goroll at uplex.de
Wed Jun 10 07:53:06 UTC 2020

commit 90c5be03d9514b45fe26c5ee029857841aef0241
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Wed Jun 10 09:44:40 2020 +0200

    shard: add error message for invalid weight
    This was brought up by Dridi in an email response to
    Initially, I also thought that we should VRT_fail() for an invalid
    parameter, but on second thought I realized that, as the shard director
    supports request-time reconfiguration, graceful error handling should be
    possible, so VRT_fail() is too hard.
    I think that even returning false for .add_backend() is too harsh, as an
    invalid weight is probably not too much of an issue to abort the
    reconfiguration in the case of caller error handling.
    That said, this might all be over the top. But I really do not want to
    run into the (still unfixed) case I saw recently trying to base64 decode
    an invalid input, which is not possible to handle gracefully.

diff --git a/lib/libvmod_directors/vmod_shard.c b/lib/libvmod_directors/vmod_shard.c
index 6e59044d6..156479eb2 100644
--- a/lib/libvmod_directors/vmod_shard.c
+++ b/lib/libvmod_directors/vmod_shard.c
@@ -315,8 +315,13 @@ vmod_shard_add_backend(VRT_CTX, struct vmod_directors_shard *vshard,
 		return (0);
-	if (args->valid_weight && args->weight > 1)
-		weight = args->weight;
+	if (args->valid_weight) {
+		if (args->weight >= 1)
+			weight = args->weight;
+		else
+			shard_err(ctx, vshard->shardd,
+			    ".add_backend(weight=%f) ignored", args->weight);
+	}
 	return shardcfg_add_backend(ctx, args->arg1,
 	    vshard->shardd, args->backend,

More information about the varnish-commit mailing list