Commit f124895f authored by Poul-Henning Kamp's avatar Poul-Henning Kamp Committed by Tollef Fog Heen

Register buffer allocation failuers on vgz's and make failure

to clean those up non-fatal.

Fixes	#1036

Conflicts:

	bin/varnishd/cache_gzip.c
parent e5e7c230
...@@ -82,6 +82,7 @@ struct vgz { ...@@ -82,6 +82,7 @@ struct vgz {
const char *id; const char *id;
struct ws *tmp; struct ws *tmp;
char *tmp_snapshot; char *tmp_snapshot;
const char *error;
struct storage *obuf; struct storage *obuf;
...@@ -263,8 +264,10 @@ VGZ_ObufStorage(const struct sess *sp, struct vgz *vg) ...@@ -263,8 +264,10 @@ VGZ_ObufStorage(const struct sess *sp, struct vgz *vg)
struct storage *st; struct storage *st;
st = FetchStorage(sp, 0); st = FetchStorage(sp, 0);
if (st == NULL) if (st == NULL) {
vg->error = "Could not get ObufStorage";
return (-1); return (-1);
}
vg->obuf = st; vg->obuf = st;
VGZ_Obuf(vg, st->ptr + st->len, st->space - st->len); VGZ_Obuf(vg, st->ptr + st->len, st->space - st->len);
...@@ -409,6 +412,7 @@ void ...@@ -409,6 +412,7 @@ void
VGZ_Destroy(struct vgz **vgp) VGZ_Destroy(struct vgz **vgp)
{ {
struct vgz *vg; struct vgz *vg;
const char *err;
vg = *vgp; vg = *vgp;
CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC); CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC);
...@@ -421,12 +425,13 @@ VGZ_Destroy(struct vgz **vgp) ...@@ -421,12 +425,13 @@ VGZ_Destroy(struct vgz **vgp)
(intmax_t)vg->vz.start_bit, (intmax_t)vg->vz.start_bit,
(intmax_t)vg->vz.last_bit, (intmax_t)vg->vz.last_bit,
(intmax_t)vg->vz.stop_bit); (intmax_t)vg->vz.stop_bit);
err = vg->error;
if (vg->tmp != NULL) if (vg->tmp != NULL)
WS_Reset(vg->tmp, vg->tmp_snapshot); WS_Reset(vg->tmp, vg->tmp_snapshot);
if (vg->dir == VGZ_GZ) if (vg->dir == VGZ_GZ)
AZ(deflateEnd(&vg->vz)); assert(deflateEnd(&vg->vz) == 0 || err != NULL);
else else
AZ(inflateEnd(&vg->vz)); assert(inflateEnd(&vg->vz) == 0 || err != NULL);
FREE_OBJ(vg); FREE_OBJ(vg);
} }
...@@ -566,18 +571,21 @@ vfp_gzip_end(struct sess *sp) ...@@ -566,18 +571,21 @@ vfp_gzip_end(struct sess *sp)
int i; int i;
vg = sp->wrk->vgz_rx; vg = sp->wrk->vgz_rx;
sp->wrk->vgz_rx = NULL;
CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC); CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC);
do { sp->wrk->vgz_rx = NULL;
VGZ_Ibuf(vg, "", 0);
if (VGZ_ObufStorage(sp, vg)) if (vg->error == NULL) {
return (-1); do {
i = VGZ_Gzip(vg, &dp, &dl, VGZ_FINISH); VGZ_Ibuf(vg, "", 0);
sp->obj->len += dl; if (VGZ_ObufStorage(sp, vg))
} while (i != Z_STREAM_END); return (-1);
if (sp->wrk->do_stream) i = VGZ_Gzip(vg, &dp, &dl, VGZ_FINISH);
RES_StreamPoll(sp); sp->obj->len += dl;
VGZ_UpdateObj(vg, sp->obj); } while (i != Z_STREAM_END);
if (sp->wrk->do_stream)
RES_StreamPoll(sp);
VGZ_UpdateObj(vg, sp->obj);
}
VGZ_Destroy(&vg); VGZ_Destroy(&vg);
return (0); return (0);
} }
...@@ -621,6 +629,7 @@ vfp_testgzip_bytes(struct sess *sp, struct http_conn *htc, ssize_t bytes) ...@@ -621,6 +629,7 @@ vfp_testgzip_bytes(struct sess *sp, struct http_conn *htc, ssize_t bytes)
st = FetchStorage(sp, 0); st = FetchStorage(sp, 0);
if (st == NULL) { if (st == NULL) {
htc->error = "Could not get storage"; htc->error = "Could not get storage";
vg->error = htc->error;
return (-1); return (-1);
} }
l = st->space - st->len; l = st->space - st->len;
......
varnishtest "Test case for #1036"
server s1 {
rxreq
# Send a bodylen of 1,5M, which will exceed cache space of 1M
non-fatal
txresp -bodylen 1572864
} -start
varnish v1 -arg "-smalloc,1M" -arg "-pgzip_level=0" -vcl+backend {
sub vcl_fetch {
set beresp.do_gzip = true;
}
} -start
client c1 {
txreq
rxresp
expect resp.status == "503"
} -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