[master] d4a28b987 add error checking and accounting for sending proxy headers

Nils Goroll nils.goroll at uplex.de
Wed Jan 15 16:12:08 UTC 2020


commit d4a28b98783786cc25012035b700c9c14c4bcf7f
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Fri Nov 30 21:08:54 2018 +0100

    add error checking and accounting for sending proxy headers

diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index d1c4b90b7..31767b4a1 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -172,8 +172,27 @@ vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo,
 	bp->vsc->req++;
 	Lck_Unlock(&bp->mtx);
 
+	err = 0;
 	if (bp->proxy_header != 0)
-		VPX_Send_Proxy(*fdp, bp->proxy_header, bo->sp);
+		err += VPX_Send_Proxy(*fdp, bp->proxy_header, bo->sp);
+	if (err < 0) {
+		VSLb(bo->vsl, SLT_FetchError,
+		     "backend %s: proxy write errno %d (%s)",
+		     VRT_BACKEND_string(bp->director),
+		     errno, vstrerror(errno));
+		// account as if connect failed - good idea?
+		VSC_C_main->backend_fail++;
+		bo->htc = NULL;
+		VTP_Close(&pfd);
+		AZ(pfd);
+		Lck_Lock(&bp->mtx);
+		bp->n_conn--;
+		bp->vsc->conn--;
+		bp->vsc->req--;
+		Lck_Unlock(&bp->mtx);
+		return (NULL);
+	}
+	bo->acct.bereq_hdrbytes += err;
 
 	PFD_LocalName(pfd, abuf1, sizeof abuf1, pbuf1, sizeof pbuf1);
 	PFD_RemoteName(pfd, abuf2, sizeof abuf2, pbuf2, sizeof pbuf2);
diff --git a/bin/varnishd/cache/cache_transport.h b/bin/varnishd/cache/cache_transport.h
index 5da5e3501..2551665b5 100644
--- a/bin/varnishd/cache/cache_transport.h
+++ b/bin/varnishd/cache/cache_transport.h
@@ -75,7 +75,7 @@ void H2_PU_Sess(struct worker *, struct sess *, struct req *);
 void H2_OU_Sess(struct worker *, struct sess *, struct req *);
 
 const struct transport *XPORT_ByNumber(uint16_t no);
-void VPX_Send_Proxy(int fd, int version, const struct sess *);
+int VPX_Send_Proxy(int fd, int version, const struct sess *);
 
 /* cache_session.c */
 struct sess *SES_New(struct pool *);
diff --git a/bin/varnishd/proxy/cache_proxy_proto.c b/bin/varnishd/proxy/cache_proxy_proto.c
index dcb4a3de9..0c829dc11 100644
--- a/bin/varnishd/proxy/cache_proxy_proto.c
+++ b/bin/varnishd/proxy/cache_proxy_proto.c
@@ -689,14 +689,14 @@ VPX_Format_Proxy(struct vsb *vsb, int version,
 		WRONG("Wrong proxy version");
 }
 
-void
+int
 VPX_Send_Proxy(int fd, int version, const struct sess *sp)
 {
 	struct vsb *vsb, *vsb2;
 	struct suckaddr *sac, *sas;
 	char ha[VTCP_ADDRBUFSIZE];
 	char pa[VTCP_PORTBUFSIZE];
-	int proto;
+	int proto, r;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	assert(version == 1 || version == 2);
@@ -720,11 +720,11 @@ VPX_Send_Proxy(int fd, int version, const struct sess *sp)
 	} else
 		WRONG("Wrong proxy version");
 
-	(void)write(fd, VSB_data(vsb), VSB_len(vsb));
+	r = write(fd, VSB_data(vsb), VSB_len(vsb));
 
 	if (!DO_DEBUG(DBG_PROTOCOL)) {
 		VSB_delete(vsb);
-		return;
+		return (r);
 	}
 
 	vsb2 = VSB_new_auto();
@@ -735,4 +735,5 @@ VPX_Send_Proxy(int fd, int version, const struct sess *sp)
 	VSL(SLT_Debug, 999, "PROXY_HDR %s", VSB_data(vsb2));
 	VSB_delete(vsb);
 	VSB_delete(vsb2);
+	return (r);
 }


More information about the varnish-commit mailing list