[master] d49025519 Teach varnishtest about SO_RCVBUF
Nils Goroll
nils.goroll at uplex.de
Wed Apr 24 11:41:08 UTC 2019
commit d4902551998a6c57aa3d56332ce888c25d134ddf
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Wed Apr 17 13:48:19 2019 +0200
Teach varnishtest about SO_RCVBUF
For now the varnishd handling of SO_SNDBUF lives in vmod-debug but could
be promoted to vmod-vtc to be usable out of tree too.
diff --git a/bin/varnishtest/tests/s00010.vtc b/bin/varnishtest/tests/s00010.vtc
new file mode 100644
index 000000000..1c21dd58b
--- /dev/null
+++ b/bin/varnishtest/tests/s00010.vtc
@@ -0,0 +1,46 @@
+varnishtest "client h1 send timeouts"
+
+server s1 {
+ rxreq
+ txresp -bodylen 100000
+} -start
+
+varnish v1 -vcl+backend {
+ import debug;
+
+ sub vcl_deliver {
+ debug.sndbuf(128b);
+ }
+} -start
+
+varnish v1 -cliok "param.set send_timeout 1"
+
+logexpect l1 -v v1 {
+ expect * * Debug "Hit total send timeout"
+} -start
+
+client c1 -rcvbuf 128 {
+ txreq
+ rxresphdrs
+ # keep the session open for 2 seconds
+ delay 2
+} -run
+
+logexpect l1 -wait
+
+feature SO_RCVTIMEO_WORKS
+varnish v1 -cliok "param.set idle_send_timeout 1"
+varnish v1 -cliok "param.reset send_timeout"
+
+logexpect l2 -v v1 {
+ expect * * Debug "Hit idle send timeout"
+} -start
+
+client c2 -rcvbuf 128 {
+ txreq
+ rxresphdrs
+ # keep the session open for 2 seconds
+ delay 2
+} -run
+
+logexpect l2 -wait
diff --git a/bin/varnishtest/vtc.h b/bin/varnishtest/vtc.h
index c091afe40..9d19f09aa 100644
--- a/bin/varnishtest/vtc.h
+++ b/bin/varnishtest/vtc.h
@@ -88,7 +88,7 @@ void init_server(void);
void init_syslog(void);
int http_process(struct vtclog *vl, const char *spec, int sock, int *sfd,
- const char *addr);
+ const char *addr, int rcvbuf);
char * synth_body(const char *len, int rnd);
diff --git a/bin/varnishtest/vtc_client.c b/bin/varnishtest/vtc_client.c
index 7d199d2ef..865b7872d 100644
--- a/bin/varnishtest/vtc_client.c
+++ b/bin/varnishtest/vtc_client.c
@@ -54,6 +54,7 @@ struct client {
char *spec;
char connect[256];
+ int rcvbuf;
char *proxy_spec;
int proxy_version;
@@ -233,10 +234,12 @@ client_thread(void *priv)
if (c->proxy_spec != NULL)
client_proxy(vl, fd, c->proxy_version, c->proxy_spec);
if (! c->keepalive)
- fd = http_process(vl, c->spec, fd, NULL, addr);
+ fd = http_process(vl, c->spec, fd, NULL, addr,
+ c->rcvbuf);
else
while (fd >= 0 && u++ < c->repeat)
- fd = http_process(vl, c->spec, fd, NULL, addr);
+ fd = http_process(vl, c->spec, fd, NULL, addr,
+ c->rcvbuf);
vtc_log(vl, 3, "closing fd %d", fd);
VTCP_close(&fd);
}
@@ -402,6 +405,11 @@ cmd_client(CMD_ARGS)
c->keepalive = 1;
continue;
}
+ if (!strcmp(*av, "-rcvbuf")) {
+ c->rcvbuf = atoi(av[1]);
+ av++;
+ continue;
+ }
if (!strcmp(*av, "-start")) {
client_start(c);
continue;
diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c
index 7df5a472b..99b46eaf2 100644
--- a/bin/varnishtest/vtc_http.c
+++ b/bin/varnishtest/vtc_http.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2008-2015 Varnish Software AS
+ * Copyright (c) 2008-2019 Varnish Software AS
* All rights reserved.
*
* Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
@@ -1905,10 +1905,11 @@ http_process_cleanup(void *arg)
int
http_process(struct vtclog *vl, const char *spec, int sock, int *sfd,
- const char *addr)
+ const char *addr, int rcvbuf)
{
struct http *hp;
- int retval;
+ int retval, oldbuf;
+ socklen_t intlen = sizeof(int);
(void)sfd;
ALLOC_OBJ(hp, HTTP_MAGIC);
@@ -1916,6 +1917,18 @@ http_process(struct vtclog *vl, const char *spec, int sock, int *sfd,
hp->fd = sock;
hp->timeout = vtc_maxdur * 1000 / 2;
+ if (rcvbuf) {
+ hp->rcvbuf = rcvbuf;
+
+ oldbuf = 0;
+ AZ(getsockopt(hp->fd, SOL_SOCKET, SO_RCVBUF, &oldbuf, &intlen));
+ AZ(setsockopt(hp->fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, intlen));
+ AZ(getsockopt(hp->fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, &intlen));
+
+ vtc_log(vl, 3, "-rcvbuf fd=%d old=%d new=%d actual=%d",
+ hp->fd, oldbuf, hp->rcvbuf, rcvbuf);
+ }
+
hp->nrxbuf = 2048*1024;
hp->rx_b = malloc(hp->nrxbuf);
AN(hp->rx_b);
diff --git a/bin/varnishtest/vtc_http.h b/bin/varnishtest/vtc_http.h
index 4db97a82f..d9241ff2b 100644
--- a/bin/varnishtest/vtc_http.h
+++ b/bin/varnishtest/vtc_http.h
@@ -38,6 +38,7 @@ struct http {
struct vsb *vsb;
+ int rcvbuf;
int nrxbuf;
char *rx_b;
char *rx_p;
diff --git a/bin/varnishtest/vtc_server.c b/bin/varnishtest/vtc_server.c
index 1a7c06f87..9003516c4 100644
--- a/bin/varnishtest/vtc_server.c
+++ b/bin/varnishtest/vtc_server.c
@@ -57,6 +57,7 @@ struct server {
int depth;
int sock;
int fd;
+ int rcvbuf;
char listen[256];
char aaddr[32];
char aport[32];
@@ -248,11 +249,12 @@ server_thread(void *priv)
} else
vtc_log(vl, 3, "accepted fd %d 0.0.0.0 0", fd);
if (! s->keepalive)
- fd = http_process(vl, s->spec, fd, &s->sock, s->listen);
+ fd = http_process(vl, s->spec, fd, &s->sock, s->listen,
+ s->rcvbuf);
else
while (fd >= 0 && i++ < s->repeat)
fd = http_process(vl, s->spec, fd,
- &s->sock, s->listen);
+ &s->sock, s->listen, s->rcvbuf);
vtc_log(vl, 3, "shutting fd %d", fd);
j = shutdown(fd, SHUT_WR);
if (!VTCP_Check(j))
@@ -300,7 +302,7 @@ server_dispatch_wrk(void *priv)
fd = s->fd;
vtc_log(vl, 3, "start with fd %d", fd);
- fd = http_process(vl, s->spec, fd, &s->sock, s->listen);
+ fd = http_process(vl, s->spec, fd, &s->sock, s->listen, s->rcvbuf);
vtc_log(vl, 3, "shutting fd %d", fd);
j = shutdown(fd, SHUT_WR);
if (!VTCP_Check(j))
@@ -541,6 +543,11 @@ cmd_server(CMD_ARGS)
av++;
continue;
}
+ if (!strcmp(*av, "-rcvbuf")) {
+ s->rcvbuf = atoi(av[1]);
+ av++;
+ continue;
+ }
if (!strcmp(*av, "-start")) {
server_start(s);
continue;
diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc
index 0cd1963c7..20ee901da 100644
--- a/lib/libvmod_debug/vmod.vcc
+++ b/lib/libvmod_debug/vmod.vcc
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2010-2015 Varnish Software AS
+# Copyright (c) 2010-2019 Varnish Software AS
# All rights reserved.
#
# Author: Poul-Henning Kamp <phk at FreeBSD.org>
@@ -251,3 +251,5 @@ Prevent VCL from going cold
$Function VOID release_vcl_busy()
Allow VCL to go cold
+
+$Function VOID sndbuf(BYTES sndbuf)
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index fc9720a74..870250ce3 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2012-2015 Varnish Software AS
+ * Copyright (c) 2012-2019 Varnish Software AS
* All rights reserved.
*
* Author: Poul-Henning Kamp <phk at FreeBSD.org>
@@ -807,3 +807,39 @@ xyzzy_release_vcl_busy(VRT_CTX)
VRT_VCL_Unbusy(ctx);
}
+
+VCL_VOID
+xyzzy_sndbuf(VRT_CTX, VCL_BYTES buflen)
+{
+ int fd = -1, oldbuf, newbuf;
+ socklen_t intlen = sizeof(int);
+
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+
+ if (ctx->bo) {
+ CHECK_OBJ(ctx->bo, BUSYOBJ_MAGIC);
+ INCOMPL();
+ }
+ else if (ctx->req) {
+ CHECK_OBJ(ctx->req, REQ_MAGIC);
+ CHECK_OBJ(ctx->req->sp, SESS_MAGIC);
+ fd = ctx->req->sp->fd;
+ }
+ else {
+ VRT_fail(ctx, "debug.sndbuf() called outside a transaction.");
+ return;
+ }
+
+ xxxassert(fd >= 0);
+
+ oldbuf = 0;
+ AZ(getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &oldbuf, &intlen));
+
+ newbuf = buflen;
+ AZ(setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &newbuf, intlen));
+ AZ(getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &newbuf, &intlen));
+
+ AN(ctx->vsl);
+ VSLb(ctx->vsl, SLT_Debug, "SO_SNDBUF fd=%d old=%d new=%ld actual=%d",
+ fd, oldbuf, buflen, newbuf);
+}
More information about the varnish-commit
mailing list