Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call VDP_Close() for all cases and revert regression #4068

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion bin/varnishd/cache/cache_deliver_proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ VDP_Panic(struct vsb *vsb, const struct vdp_ctx *vdc)
VSB_cat(vsb, "},\n");
}


/*
* Ensure that transports have called VDP_Close()
* to avoid leaks in VDPs
*/
void
VDP_Fini(struct vdp_ctx *vdc)
{
assert(VTAILQ_EMPTY(&vdc->vdp));
}

void
VDP_Init(struct vdp_ctx *vdc, struct worker *wrk, struct vsl_log *vsl,
Expand Down
34 changes: 23 additions & 11 deletions bin/varnishd/cache/cache_esi_deliver.c
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,17 @@ static const struct vdp ved_ved = {
.fini = ved_vdp_fini,
};

static void
ved_close(struct req *req, struct boc *boc, int error)
{
req->acct.resp_bodybytes += VDP_Close(req->vdc, req->objcore, boc);

if (! error)
return;
req->top->topreq->vdc->retval = -1;
req->top->topreq->doclose = req->doclose;
}

/*--------------------------------------------------------------------*/

static void v_matchproto_(vtr_deliver_f)
Expand All @@ -868,19 +879,22 @@ ved_deliver(struct req *req, struct boc *boc, int wantbody)

CAST_OBJ_NOTNULL(ecx, req->transport_priv, ECX_MAGIC);

if (wantbody == 0)
if (wantbody == 0) {
ved_close(req, boc, 0);
return;
}

status = req->resp->status % 1000;

if (!ecx->incl_cont && status != 200 && status != 204) {
req->top->topreq->vdc->retval = -1;
req->top->topreq->doclose = req->doclose;
ved_close(req, boc, 1);
return;
}

if (boc == NULL && ObjGetLen(req->wrk, req->objcore) == 0)
if (boc == NULL && ObjGetLen(req->wrk, req->objcore) == 0) {
ved_close(req, boc, 0);
return;
}

if (http_GetHdr(req->resp, H_Content_Encoding, &p))
i = http_coding_eq(p, gzip);
Expand All @@ -899,7 +913,10 @@ ved_deliver(struct req *req, struct boc *boc, int wantbody)

if (req->objcore->flags & OC_F_FAILED) {
/* No way of signalling errors in the middle of
the ESI body. Omit this ESI fragment. */
* the ESI body. Omit this ESI fragment.
* XXX change error argument to 1
*/
ved_close(req, boc, 0);
return;
}

Expand All @@ -926,10 +943,5 @@ ved_deliver(struct req *req, struct boc *boc, int wantbody)
if (i && req->doclose == SC_NULL)
req->doclose = SC_REM_CLOSE;

req->acct.resp_bodybytes += VDP_Close(req->vdc, req->objcore, boc);

if (i && !ecx->incl_cont) {
req->top->topreq->vdc->retval = -1;
req->top->topreq->doclose = req->doclose;
}
ved_close(req, boc, i && !ecx->incl_cont);
}
2 changes: 2 additions & 0 deletions bin/varnishd/cache/cache_req.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ Req_Cleanup(struct sess *sp, struct worker *wrk, struct req *req)
wrk->stats->ws_client_overflow++;

wrk->seen_methods = 0;

VDP_Fini(req->vdc);
}

/*----------------------------------------------------------------------
Expand Down
5 changes: 2 additions & 3 deletions bin/varnishd/cache/cache_req_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ cnt_transmit(struct worker *wrk, struct req *req)
VCL_StackVDP(req, req->vcl, req->vdp_filter_list)) {
VSLb(req->vsl, SLT_Error, "Failure to push processors");
req->doclose = SC_OVERLOAD;
req->acct.resp_bodybytes +=
VDP_Close(req->vdc, req->objcore, boc);
} else {
if (status < 200 || status == 204) {
// rfc7230,l,1691,1695
Expand Down Expand Up @@ -504,9 +506,6 @@ cnt_transmit(struct worker *wrk, struct req *req)
req->doclose = SC_TX_ERROR;
}

if (req->doclose != SC_NULL)
req->acct.resp_bodybytes += VDP_Close(req->vdc, req->objcore, boc);

if (boc != NULL)
HSH_DerefBoc(wrk, req->objcore);

Expand Down
1 change: 1 addition & 0 deletions bin/varnishd/cache/cache_varnishd.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ void VDI_Event(const struct director *d, enum vcl_event_e ev);
void VDI_Init(void);

/* cache_deliver_proc.c */
void VDP_Fini(struct vdp_ctx *vdc);
void VDP_Init(struct vdp_ctx *vdc, struct worker *wrk, struct vsl_log *vsl,
struct req *req);
uint64_t VDP_Close(struct vdp_ctx *, struct objcore *, struct boc *);
Expand Down
12 changes: 7 additions & 5 deletions bin/varnishd/http1/cache_http1_deliver.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
/*--------------------------------------------------------------------*/

static void
v1d_error(struct req *req, const char *msg)
v1d_error(struct req *req, struct boc *boc, const char *msg)
{
static const char r_500[] =
"HTTP/1.1 500 Internal Server Error\r\n"
Expand All @@ -57,6 +57,8 @@ v1d_error(struct req *req, const char *msg)
req->wrk->stats->client_resp_500++;
VTCP_Assert(write(req->sp->fd, r_500, sizeof r_500 - 1));
req->doclose = SC_TX_EOF;

req->acct.resp_bodybytes += VDP_Close(req->vdc, req->objcore, boc);
}

/*--------------------------------------------------------------------
Expand Down Expand Up @@ -98,18 +100,18 @@ V1D_Deliver(struct req *req, struct boc *boc, int sendbody)
INIT_OBJ(ctx, VRT_CTX_MAGIC);
VCL_Req2Ctx(ctx, req);
if (VDP_Push(ctx, req->vdc, req->ws, VDP_v1l, NULL)) {
v1d_error(req, "Failure to push v1d processor");
v1d_error(req, boc, "Failure to push v1d processor");
return;
}
}

if (WS_Overflowed(req->ws)) {
v1d_error(req, "workspace_client overflow");
v1d_error(req, boc, "workspace_client overflow");
return;
}

if (WS_Overflowed(req->sp->ws)) {
v1d_error(req, "workspace_session overflow");
v1d_error(req, boc, "workspace_session overflow");
return;
}

Expand All @@ -118,7 +120,7 @@ V1D_Deliver(struct req *req, struct boc *boc, int sendbody)
cache_param->http1_iovs);

if (WS_Overflowed(req->wrk->aws)) {
v1d_error(req, "workspace_thread overflow");
v1d_error(req, boc, "workspace_thread overflow");
return;
}

Expand Down