Commit b68b1451 authored by Geoff Simmons's avatar Geoff Simmons

Add the timeout parameter to the VDP object.

parent f7640fe5
......@@ -56,12 +56,17 @@ XXX ...
.. _pipe.vdp():
new xvdp = pipe.vdp(STRING path, STRING name, BYTES bufsz)
----------------------------------------------------------
new xvdp = pipe.vdp(STRING path, STRING name, BYTES bufsz, DURATION timeout)
----------------------------------------------------------------------------
::
new xvdp = pipe.vdp(STRING path, STRING name=0, BYTES bufsz=0)
new xvdp = pipe.vdp(
STRING path,
STRING name=0,
BYTES bufsz=0,
DURATION timeout=60
)
XXX ...
......
......@@ -70,6 +70,7 @@ endif
EXTRA_DIST = \
vdfp_pipe.vcc \
$(srcdir)/tests/slow.sh \
$(VMOD_TESTS)
CLEANFILES = \
......
#! /bin/sh
while read line
do
sleep 1
echo $line
done
exit 0
# looks like -*- vcl -*-
varnishtest "vdp timeouts"
server s1 {
rxreq
txresp -body {foo bar baz quux
foo bar baz quux
}
} -start
varnish v1 -vcl+backend {
import ${vmod_pipe};
sub vcl_init {
new slow = pipe.vdp(path="${testdir}/slow.sh", timeout=0.5s);
}
sub vcl_deliver {
set resp.filters = "slow";
}
} -start
client c1 {
txreq
rxresp -no_obj
expect resp.status == 200
} -run
logexpect l1 -v v1 -g vxid -d 1 -q {Notice ~ "^vdfp_pipe: vdp slow:" or Error ~ "^vdfp_pipe: vdp slow:"} {
expect 0 * Begin {^req \d+ rxreq$}
expect * = Notice {^vdfp_pipe: vdp slow: exec'd .+/slow.sh as pid \d+$}
expect * = Error {^vdfp_pipe: vdp slow: timeout waiting for .+/slow.sh$}
expect * = Notice {^vdfp_pipe: vdp slow: .+/slow.sh exited with status 0$}
expect * = End
} -run
varnish v1 -vcl+backend {
import ${vmod_pipe};
sub vcl_init {
new slow = pipe.vdp(path="${testdir}/slow.sh", timeout=2s);
}
sub vcl_deliver {
set resp.filters = "slow";
}
}
logexpect l1 -v v1 -g vxid -d 0 -q {Notice ~ "^vdfp_pipe: vdp slow:" or Error ~ "^vdfp_pipe: vdp slow:"} {
expect 0 * Begin {^req \d+ rxreq$}
expect * = Notice {^vdfp_pipe: vdp slow: exec'd .+/slow.sh as pid \d+$}
expect * = Notice {^vdfp_pipe: vdp slow: .+/slow.sh exited with status 0$}
expect * = End
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.body == {foo bar baz quux
foo bar baz quux
}
} -run
logexpect l1 -wait
varnish v1 -vcl+backend {
import ${vmod_pipe};
sub vcl_init {
new slow = pipe.vdp(path="${testdir}/slow.sh", timeout=0s);
}
sub vcl_deliver {
set resp.filters = "slow";
}
}
logexpect l1 -start
client c1 -run
logexpect l1 -wait
varnish v1 -vcl+backend {
import ${vmod_pipe};
sub vcl_init {
new slow = pipe.vdp(path="${testdir}/slow.sh", timeout=-1s);
}
sub vcl_deliver {
set resp.filters = "slow";
}
}
logexpect l1 -start
client c1 -run
logexpect l1 -wait
......@@ -53,10 +53,6 @@
#define VDPFAIL(ctx, fmt, ...) \
VFAIL((ctx), "vdp", fmt, __VA_ARGS__)
/* == default first_byte_ and between_bytes_timeout (in ms) */
#define TIMEOUT_MS 60000
/* XXX make bufsz configurable per object (and at runtime?) */
#ifdef PIPE_BUF
#define DEFAULT_BUFSZ ((size_t)PIPE_BUF)
#else
......@@ -72,6 +68,7 @@ struct VPFX(pipe_vdp) {
char **argv;
size_t bufsz;
int argc;
int tmo_ms;
};
struct vdp_map {
......@@ -356,18 +353,18 @@ vdp_bytes(struct req *req, enum vdp_action act, void **priv, const void *ptr,
fds[STDERR_FILENO].revents = 0;
errno = 0;
retval = poll(fds, 3, TIMEOUT_MS);
retval = poll(fds, 3, obj->tmo_ms);
if (retval < 0) {
assert(errno == EINTR);
continue;
}
if (retval == 0 && len > 0) {
if (retval == 0) {
if (obj->tmo_ms == 0)
continue;
VSLb(req->vsl, SLT_Error, "vdfp_pipe: vdp %s: timeout "
"waiting for %s", obj->name, obj->path);
return (-1);
}
else if (retval == 0)
continue;
for (int i = 0; i < 3; i++) {
if (fds[i].revents == 0)
......@@ -530,7 +527,8 @@ vmod_event(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
VCL_VOID
vmod_vdp__init(VRT_CTX, struct VPFX(pipe_vdp) **vdpp, const char *obj_name,
VCL_STRING path, VCL_STRING vdp_name, VCL_BYTES bufsz)
VCL_STRING path, VCL_STRING vdp_name, VCL_BYTES bufsz,
VCL_DURATION timeout)
{
struct VPFX(pipe_vdp) *vdp_obj;
struct vdp *vdp;
......@@ -585,6 +583,7 @@ vmod_vdp__init(VRT_CTX, struct VPFX(pipe_vdp) **vdpp, const char *obj_name,
vdp_obj->name = strdup(obj_name);
vdp_obj->path = strdup(path);
vdp_obj->bufsz = bufsz;
vdp_obj->tmo_ms = timeout * 1000;
errno = 0;
vdp = malloc(sizeof(*vdp));
......
......@@ -50,7 +50,7 @@ external commands.
XXX ...
$Object vdp(STRING path, STRING name=0, BYTES bufsz=0)
$Object vdp(STRING path, STRING name=0, BYTES bufsz=0, DURATION timeout=60)
XXX ...
......
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