Skip to content

Commit 725e716

Browse files
committed
varnishd: minor refractory for PROXY send error
There is no need to special case VPX_Send_Proxy with its own error handling. We can instead reuse vbe_dir_finish. We will now report BackendClosed tag in VSL as well (from vbe_dir_finish). To accomplish this we need to initialize the HTC struct a little bit earlier. Finally, we change the doclose reason to be an error transmission (SC_TX_ERROR). Signed-off-by: Asad Sajjad Ahmed <asadsa@varnish-software.com>
1 parent 268b182 commit 725e716

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

bin/varnishd/cache/cache_backend.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -380,27 +380,26 @@ vbe_dir_getfd(VRT_CTX, struct worker *wrk, VCL_BACKEND dir, struct backend *bp,
380380
bp->vsc->req++;
381381
Lck_Unlock(bp->director->mtx);
382382

383+
INIT_OBJ(bo->htc, HTTP_CONN_MAGIC);
384+
bo->htc->priv = pfd;
385+
bo->htc->rfd = fdp;
386+
bo->htc->doclose = SC_NULL;
383387
CHECK_OBJ_NOTNULL(bo->htc->doclose, STREAM_CLOSE_MAGIC);
384388

385389
err = 0;
386390
if (bp->proxy_header != 0)
387-
err += VPX_Send_Proxy(*fdp, bp->proxy_header, bo->sp);
391+
err = VPX_Send_Proxy(*fdp, bp->proxy_header, bo->sp);
388392
if (err < 0) {
389393
VSLb(bo->vsl, SLT_FetchError,
390394
"backend %s: proxy write errno %d (%s)",
391395
VRT_BACKEND_string(dir),
392396
errno, VAS_errtxt(errno));
393-
// account as if connect failed - good idea?
394-
VSC_C_main->backend_fail++;
395-
bo->htc = NULL;
396-
VCP_Close(&pfd);
397-
AZ(pfd);
397+
bo->htc->doclose = SC_TX_ERROR;
398398
Lck_Lock(bp->director->mtx);
399-
bp->n_conn--;
400-
bp->vsc->conn--;
399+
VSC_C_main->backend_fail++;
401400
bp->vsc->req--;
402-
vbe_connwait_signal_locked(bp);
403401
Lck_Unlock(bp->director->mtx);
402+
vbe_dir_finish(ctx, dir);
404403
vbe_connwait_fini(cw);
405404
return (NULL);
406405
}
@@ -412,10 +411,6 @@ vbe_dir_getfd(VRT_CTX, struct worker *wrk, VCL_BACKEND dir, struct backend *bp,
412411
*fdp, VRT_BACKEND_string(dir), abuf2, pbuf2, abuf1, pbuf1,
413412
PFD_State(pfd) == PFD_STATE_STOLEN ? "reuse" : "connect");
414413

415-
INIT_OBJ(bo->htc, HTTP_CONN_MAGIC);
416-
bo->htc->priv = pfd;
417-
bo->htc->rfd = fdp;
418-
bo->htc->doclose = SC_NULL;
419414
FIND_TMO(first_byte_timeout,
420415
bo->htc->first_byte_timeout, bo, bp);
421416
FIND_TMO(between_bytes_timeout,

bin/varnishtest/tests/o00007.vtc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ varnish v1 -cliok "param.set debug +proxy_error"
1515
logexpect l1 -v v1 {
1616
expect * 1002 Timestamp {^Connected:}
1717
expect * 1002 FetchError {^backend default: proxy write errno}
18+
expect * 1002 BackendClose {default close TX_ERROR}
1819
} -start
1920

2021
client c1 {
@@ -27,13 +28,13 @@ logexpect l1 -wait
2728

2829
varnish v1 -expect MAIN.backend_conn == 1
2930
varnish v1 -expect MAIN.backend_req == 0
30-
varnish v1 -expect MAIN.backend_closed == 0
31-
varnish v1 -expect MAIN.backend_closed_err == 0
31+
varnish v1 -expect MAIN.backend_closed == 1
32+
varnish v1 -expect MAIN.backend_closed_err == 1
3233

3334
varnish v1 -expect MAIN.bc_rx_bad == 0
3435
varnish v1 -expect MAIN.bc_rem_close == 0
3536
varnish v1 -expect MAIN.bc_rx_timeout == 0
36-
varnish v1 -expect MAIN.bc_tx_error == 0
37+
varnish v1 -expect MAIN.bc_tx_error == 1
3738
varnish v1 -expect MAIN.bc_tx_proxy == 0
3839

3940
varnish v1 -expect VBE.vcl1.default.conn == 0

0 commit comments

Comments
 (0)