Commit d4902551 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune Committed by Nils Goroll

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.
parent 654f0b5f
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
......@@ -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);
......
......@@ -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;
......
/*-
* Copyright (c) 2008-2015 Varnish Software AS
* Copyright (c) 2008-2019 Varnish Software AS
* All rights reserved.
*
* Author: Poul-Henning Kamp <phk@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);
......
......@@ -38,6 +38,7 @@ struct http {
struct vsb *vsb;
int rcvbuf;
int nrxbuf;
char *rx_b;
char *rx_p;
......
......@@ -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;
......
#
# Copyright (c) 2010-2015 Varnish Software AS
# Copyright (c) 2010-2019 Varnish Software AS
# All rights reserved.
#
# Author: Poul-Henning Kamp <phk@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)
/*-
* Copyright (c) 2012-2015 Varnish Software AS
* Copyright (c) 2012-2019 Varnish Software AS
* All rights reserved.
*
* Author: Poul-Henning Kamp <phk@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);
}
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