Commit 8361777c authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Deal with backend connection errors while fetching the body.

Eventually, VCL should get a say in this.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@1079 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 5579def9
...@@ -280,8 +280,16 @@ cnt_fetch(struct sess *sp) ...@@ -280,8 +280,16 @@ cnt_fetch(struct sess *sp)
return (0); return (0);
} }
if (sp->handling == VCL_RET_INSERT) { if (sp->handling == VCL_RET_INSERT) {
if (FetchBody(sp)) {
sp->obj->cacheable = 0;
HSH_Unbusy(sp->obj);
HSH_Deref(sp->obj);
sp->obj = NULL;
RES_Error(sp, 503, NULL);
sp->step = STP_DONE;
return (0);
}
sp->obj->cacheable = 1; sp->obj->cacheable = 1;
FetchBody(sp);
AZ(sp->vbc); AZ(sp->vbc);
HSH_Ref(sp->obj); /* get another, STP_DELIVER will deref */ HSH_Ref(sp->obj); /* get another, STP_DELIVER will deref */
HSH_Unbusy(sp->obj); HSH_Unbusy(sp->obj);
......
...@@ -45,7 +45,8 @@ fetch_straight(const struct sess *sp, int fd, struct http *hp, char *b) ...@@ -45,7 +45,8 @@ fetch_straight(const struct sess *sp, int fd, struct http *hp, char *b)
while (cl > 0) { while (cl > 0) {
i = http_Read(hp, fd, p, cl); i = http_Read(hp, fd, p, cl);
xxxassert(i > 0); /* XXX seen */ if (i <= 0)
return (-1);
p += i; p += i;
cl -= i; cl -= i;
} }
...@@ -86,7 +87,8 @@ fetch_chunked(const struct sess *sp, int fd, struct http *hp) ...@@ -86,7 +87,8 @@ fetch_chunked(const struct sess *sp, int fd, struct http *hp)
if (q == NULL || q == buf || *q != '\n') { if (q == NULL || q == buf || *q != '\n') {
xxxassert(be > bp); xxxassert(be > bp);
i = http_Read(hp, fd, bp, be - bp); i = http_Read(hp, fd, bp, be - bp);
xxxassert(i >= 0); if (i <= 0)
return (-1);
bp += i; bp += i;
continue; continue;
} }
...@@ -135,6 +137,8 @@ fetch_chunked(const struct sess *sp, int fd, struct http *hp) ...@@ -135,6 +137,8 @@ fetch_chunked(const struct sess *sp, int fd, struct http *hp)
/* Pick up the rest of this chunk */ /* Pick up the rest of this chunk */
while (v > 0) { while (v > 0) {
i = http_Read(hp, fd, st->ptr + st->len, v); i = http_Read(hp, fd, st->ptr + st->len, v);
if (i <= 0)
return (-1);
st->len += i; st->len += i;
sp->obj->len += i; sp->obj->len += i;
u -= i; u -= i;
...@@ -190,9 +194,10 @@ fetch_eof(const struct sess *sp, int fd, struct http *hp) ...@@ -190,9 +194,10 @@ fetch_eof(const struct sess *sp, int fd, struct http *hp)
AN(p); AN(p);
AN(st); AN(st);
i = http_Read(hp, fd, p, v); i = http_Read(hp, fd, p, v);
xxxassert(i >= 0); if (i < 0)
return (-1);
if (i == 0) if (i == 0)
break; break;
p += i; p += i;
v -= i; v -= i;
st->len += i; st->len += i;
...@@ -218,6 +223,7 @@ FetchBody(struct sess *sp) ...@@ -218,6 +223,7 @@ FetchBody(struct sess *sp)
char *b; char *b;
int body = 1; /* XXX */ int body = 1; /* XXX */
struct http *hp; struct http *hp;
struct storage *st;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
...@@ -248,9 +254,19 @@ FetchBody(struct sess *sp) ...@@ -248,9 +254,19 @@ FetchBody(struct sess *sp)
} else } else
cls = 0; cls = 0;
if (cls < 0) {
while (!TAILQ_EMPTY(&sp->obj->store)) {
st = TAILQ_FIRST(&sp->obj->store);
TAILQ_REMOVE(&sp->obj->store, st, list);
stevedore->free(st);
}
close(vc->fd);
VBE_ClosedFd(sp->wrk, vc, 1);
return (-1);
}
{ {
/* Sanity check fetch methods accounting */ /* Sanity check fetch methods accounting */
struct storage *st;
unsigned uu; unsigned uu;
uu = 0; uu = 0;
......
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