use the single remaining healthy backend.
Add regression test.
Fixes: ticket #306
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3174
d4fa192b-c00b-0410-8231-
f00ffab90ce4
r *= s1;
s2 = 0;
- j = 0;
for (i = 0; i < vs->nhosts; i++) {
if (!vs->hosts[i].backend->healthy)
continue;
s2 += vs->hosts[i].weight;
- if (r > s2)
- j = i + 1;
+ if (r < s2)
+ break;
}
+
if (s2 != s1) {
/*
* Health bit changed in an unusable way while we
*/
continue;
}
- vbe = VBE_GetVbe(sp, vs->hosts[j].backend);
+ vbe = VBE_GetVbe(sp, vs->hosts[i].backend);
if (vbe != NULL)
return (vbe);
k++;
--- /dev/null
+# $Id: v00007.vtc 3060 2008-08-01 12:44:53Z phk $
+
+test "Regression test for ticket #306, random director ignoring good backend"
+
+server s1 {
+
+ rxreq
+ expect req.url == /foo
+ txresp -body "foo1"
+
+ rxreq
+ expect req.url == /bar
+ txresp -body "bar1"
+
+} -start
+
+server s2 -listen 127.0.0.1:9180 {
+ rxreq
+ txresp -status 404
+} -start
+
+varnish v1 -vcl {
+ backend s1 {
+ .host = "127.0.0.1"; .port = "9080";
+ }
+ backend s2 {
+ .host = "127.0.0.1"; .port = "9180";
+ .probe = {
+ .url = "/";
+ }
+ }
+ director foo random {
+ { .backend = s2; .weight = 1; }
+ { .backend = s1; .weight = 1; }
+ }
+
+ sub vcl_recv {
+ set req.backend = foo;
+ }
+} -start
+
+client c1 {
+ timeout 10
+
+ txreq -url "/foo"
+ rxresp
+ expect resp.status == 200
+
+ txreq -url "/bar"
+ rxresp
+ expect resp.status == 200
+
+} -run