Commit fb14e3b0 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Fix an off-by-one error in the random director, which made it unable to

use the single remaining healthy backend.

Add regression test.

Fixes: ticket #306



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@3174 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent c001cb9f
......@@ -96,14 +96,14 @@ vdi_random_getfd(struct sess *sp)
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
......@@ -112,7 +112,7 @@ vdi_random_getfd(struct sess *sp)
*/
continue;
}
vbe = VBE_GetVbe(sp, vs->hosts[j].backend);
vbe = VBE_GetVbe(sp, vs->hosts[i].backend);
if (vbe != NULL)
return (vbe);
k++;
......
# $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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment