From: phk Date: Mon, 18 Sep 2006 06:41:57 +0000 (+0000) Subject: Unify backend error handling X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a31d71e7dab995514b748393f6783e341ba51f7c;p=varnish Unify backend error handling git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1057 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index f8cd81ac..e791f0b1 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -297,7 +297,7 @@ void VCA_Init(void); /* cache_backend.c */ void VBE_Init(void); -struct vbe_conn *VBE_GetFd(struct backend *bp, unsigned xid); +struct vbe_conn *VBE_GetFd(struct sess *sp); void VBE_ClosedFd(struct vbe_conn *vc, int already); void VBE_RecycleFd(struct vbe_conn *vc); @@ -367,7 +367,7 @@ int PassSession(struct sess *sp); void PassBody(struct sess *sp); /* cache_pipe.c */ -void PipeSession(struct sess *sp); +int PipeSession(struct sess *sp); /* cache_pool.c */ void WRK_Init(void); diff --git a/varnish-cache/bin/varnishd/cache_backend.c b/varnish-cache/bin/varnishd/cache_backend.c index 6033b54b..4a584c5a 100644 --- a/varnish-cache/bin/varnishd/cache_backend.c +++ b/varnish-cache/bin/varnishd/cache_backend.c @@ -175,12 +175,15 @@ vbe_connect(struct backend *bp) * new connection. */ -struct vbe_conn * -VBE_GetFd(struct backend *bp, unsigned xid) +static struct vbe_conn * +vbe_nextfd(struct sess *sp) { struct vbe_conn *vc, *vc2; struct pollfd pfd; + struct backend *bp; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + bp = sp->backend; CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); while (1) { /* @@ -245,12 +248,29 @@ VBE_GetFd(struct backend *bp, unsigned xid) if (vc != NULL ) { assert(vc->fd >= 0); VSL_stats->backend_conn++; - VSL(SLT_BackendXID, vc->fd, "%u", xid); + WSL(sp->wrk, SLT_BackendXID, vc->fd, "%u", sp->xid); AN(vc->backend); } return (vc); } +/*--------------------------------------------------------------------*/ + +struct vbe_conn * +VBE_GetFd(struct sess *sp) +{ + struct vbe_conn *vc; + + vc = vbe_nextfd(sp); + if (vc != NULL) { + WSL(sp->wrk, SLT_Backend, sp->fd, "%d %s", vc->fd, + sp->backend->vcl_name); + return (vc); + } + RES_Error(sp, 503, "Backend did not respond."); + return (NULL); +} + /* Close a connection ------------------------------------------------*/ void diff --git a/varnish-cache/bin/varnishd/cache_center.c b/varnish-cache/bin/varnishd/cache_center.c index b2bbfedb..4c411659 100644 --- a/varnish-cache/bin/varnishd/cache_center.c +++ b/varnish-cache/bin/varnishd/cache_center.c @@ -530,7 +530,14 @@ cnt_miss(struct sess *sp) INCOMPL(); if (sp->handling == VCL_RET_FETCH) { AZ(sp->vbc); - FetchHeaders(sp); + if (FetchHeaders(sp)) { + sp->obj->cacheable = 0; + HSH_Unbusy(sp->obj); + HSH_Deref(sp->obj); + sp->obj = NULL; + sp->step = STP_DONE; + return (0); + } sp->step = STP_FETCH; AN(sp->vbc); return (0); @@ -613,7 +620,7 @@ cnt_pipe(struct sess *sp) { sp->wrk->acct.pipe++; - PipeSession(sp); + (void)PipeSession(sp); sp->step = STP_DONE; return (0); } diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index 1ad353f1..ed417f7a 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -290,11 +290,9 @@ FetchHeaders(struct sess *sp) sp->obj->xid = sp->xid; - vc = VBE_GetFd(sp->backend, sp->xid); + vc = VBE_GetFd(sp); if (vc == NULL) - vc = VBE_GetFd(sp->backend, sp->xid); - XXXAN(vc); - WSL(w, SLT_Backend, sp->fd, "%d %s", vc->fd, sp->backend->vcl_name); + return (1); http_ClrHeader(vc->http); vc->http->logtag = HTTP_Tx; diff --git a/varnish-cache/bin/varnishd/cache_pass.c b/varnish-cache/bin/varnishd/cache_pass.c index dca4425f..589c1980 100644 --- a/varnish-cache/bin/varnishd/cache_pass.c +++ b/varnish-cache/bin/varnishd/cache_pass.c @@ -202,12 +202,9 @@ PassSession(struct sess *sp) CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); w = sp->wrk; - vc = VBE_GetFd(sp->backend, sp->xid); - if (vc == NULL) { - RES_Error(sp, 503, "Backend did not respond."); + vc = VBE_GetFd(sp); + if (vc == NULL) return (1); - } - WSL(w, SLT_Backend, sp->fd, "%d %s", vc->fd, sp->backend->vcl_name); http_CopyReq(w, vc->fd, vc->http, sp->http); http_FilterHeader(w, vc->fd, vc->http, sp->http, HTTPH_R_PASS); diff --git a/varnish-cache/bin/varnishd/cache_pipe.c b/varnish-cache/bin/varnishd/cache_pipe.c index 78c58986..e1747a1d 100644 --- a/varnish-cache/bin/varnishd/cache_pipe.c +++ b/varnish-cache/bin/varnishd/cache_pipe.c @@ -40,7 +40,7 @@ rdf(struct pollfd *fds, int idx) } } -void +int PipeSession(struct sess *sp) { struct vbe_conn *vc; @@ -53,12 +53,9 @@ PipeSession(struct sess *sp) CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); w = sp->wrk; - vc = VBE_GetFd(sp->backend, sp->xid); - if (vc == NULL) { - RES_Error(sp, 503, "Backend did not respond."); - return; - } - VSL(SLT_Backend, sp->fd, "%d %s", vc->fd, sp->backend->vcl_name); + vc = VBE_GetFd(sp); + if (vc == NULL) + return (1); vc->http->logtag = HTTP_Tx; http_CopyReq(w, vc->fd, vc->http, sp->http); diff --git a/varnish-cache/bin/varnishd/cache_response.c b/varnish-cache/bin/varnishd/cache_response.c index bb7e8467..c9244731 100644 --- a/varnish-cache/bin/varnishd/cache_response.c +++ b/varnish-cache/bin/varnishd/cache_response.c @@ -103,7 +103,7 @@ RES_Error(struct sess *sp, int code, const char *expl) vsb_cat(sb, "Server: Varnish\r\n" "Connection: close\r\n" - "content-Type: text/html; charset=iso-8859-1\r\n" + "Content-Type: text/html; charset=iso-8859-1\r\n" "\r\n" "\r\n" "\r\n"