[PATCH 3/4] Close with a 500 response on client ws overflow.

Lasse Karstensen lkarsten at varnish-software.com
Fri Jul 31 09:48:45 CEST 2015


---
 bin/varnishd/cache/cache_req_fsm.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 46f777e..0a94850 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -112,6 +112,10 @@ static enum req_fsm_nxt
 cnt_deliver(struct worker *wrk, struct req *req)
 {
 	struct busyobj *bo;
+	char r_500[] =
+		"HTTP/1.1 500 Internal Server Error\r\n"
+		"Server: Varnish\r\n"
+		"Connection: close\r\n\r\n";
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
@@ -181,6 +185,28 @@ cnt_deliver(struct worker *wrk, struct req *req)
 
 	assert(wrk->handling == VCL_RET_DELIVER);
 
+	/* Make sure there is room in the ws left for delivery processors
+	 * (40 bytes each) and VSL buffering for Etag weakening and SetH().
+	 */
+	if (pdiff(req->ws->f, req->ws->e) < sizeof(struct vdp_entry)*3+128) {
+		VSLb(req->vsl, SLT_Error,
+		    "Inferred workspace_client overflow.");
+		WS_MarkOverflow(req->ws);
+	}
+
+	if (WS_Overflowed(req->ws)) {
+		VSLb(req->vsl, SLT_Error, "workspace_client overflow");
+		VSLb(req->vsl, SLT_RespProtocol, "HTTP/1.1");
+		VSLb(req->vsl, SLT_RespStatus, "500");
+		VSLb(req->vsl, SLT_RespReason, "Internal Server Error");
+
+		(void)write(req->sp->fd, r_500, strlen(r_500));
+		VSLb_ts_req(req, "Resp", W_TIM_real(wrk));
+		http_Teardown(req->resp);
+		SES_Close(req->sp, SC_OVERLOAD);
+		return (REQ_FSM_DONE);
+	}
+
 	if (!(req->objcore->flags & OC_F_PASS)
 	    && req->esi_level == 0
 	    && http_IsStatus(req->resp, 200)
-- 
2.1.4


-- 
Lasse Karstensen
Varnish Software AS



More information about the varnish-dev mailing list