From nils.goroll at uplex.de Thu Feb 1 13:49:06 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Thu, 1 Feb 2024 13:49:06 +0000 (UTC) Subject: [master] 98945cea5 Define a standard for RST document structure adornments Message-ID: <20240201134906.10E50112CBA@lists.varnish-cache.org> commit 98945cea5f3b3b98672b190dc78b1eb28769dc2c Author: Nils Goroll Date: Thu Feb 1 14:39:54 2024 +0100 Define a standard for RST document structure adornments ... and minor touch up of the file. No, this does not imply me checking all our RST files for adherence with this standard. Ref 0d663a5e7b53f52e1a2c94be4081eb47e9d7be4f diff --git a/doc/README.WRITING_RST.rst b/doc/README.WRITING_RST.rst index f64cab47c..21fe17a0d 100644 --- a/doc/README.WRITING_RST.rst +++ b/doc/README.WRITING_RST.rst @@ -1,5 +1,5 @@ .. - Copyright (c) 2015-2019 Varnish Software AS + Copyright 2015,2016,2019,2024 UPLEX - Nils Goroll Systemoptimierung SPDX-License-Identifier: BSD-2-Clause See LICENSE file for full text of license @@ -24,9 +24,9 @@ not follow the style: * use code blocks for:: - Examples and + Examples and - other code + other code References are tricky --------------------- @@ -70,6 +70,28 @@ of documentation: .. _implicit link targets: http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#implicit-hyperlink-targets +Document Structure +------------------ + +While RST supports a great deal of flexibility for adornments of +titles and section headers, we should adhere to a consistent style to +avoid breaking the document structure unintentially. + +Within the Varnish-Cache project, we should use these characters: + +* Over and underline ``=`` for document titles + +* Over and underline ``-`` for document subtitles + +* Underline ``=`` for sections + +* Underline ``-`` for subsection + +* Underline ``~`` for subsubsections + +This is in line with the example in +https://docutils.sourceforge.io/docs/user/rst/quickstart.html#sections + HISTORY ======= @@ -81,4 +103,5 @@ COPYRIGHT This document is licensed under the same licence as Varnish itself. See LICENCE for details. -* Copyright 2014 UPLEX - Nils Goroll Systemoptimierung +* Copyright 2015,2016,2019,2024 UPLEX - Nils Goroll + Systemoptimierung From dridi.boukelmoune at gmail.com Mon Feb 5 10:54:05 2024 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 5 Feb 2024 10:54:05 +0000 (UTC) Subject: [master] 1ff0c0f4e vrt_var: Make bereq.task_deadline unset-able Message-ID: <20240205105405.C26041036E1@lists.varnish-cache.org> commit 1ff0c0f4eefbd6392c89e7b04a775c1daf9f62b5 Author: Dridi Boukelmoune Date: Mon Feb 5 11:36:11 2024 +0100 vrt_var: Make bereq.task_deadline unset-able The other timeouts should eventually become unset-able as well, where an unset variable falls back to a parameter and zero means no timeout, overriding the fallback parameter. Refs #4043 diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c index b69005cd0..9a14519b8 100644 --- a/bin/varnishd/cache/cache_vrt_var.c +++ b/bin/varnishd/cache/cache_vrt_var.c @@ -387,7 +387,19 @@ VRT_l_client_identity(VRT_CTX, const char *str, VCL_STRANDS s) /*--------------------------------------------------------------------*/ -#define BEREQ_TIMEOUT(which) \ +#define BEREQ_TIMEOUT_UNSET0(which) + +#define BEREQ_TIMEOUT_UNSET1(which) \ +VCL_VOID \ +VRT_u_bereq_##which(VRT_CTX) \ +{ \ + \ + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \ + CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC); \ + ctx->bo->which = NAN; \ +} + +#define BEREQ_TIMEOUT(which, unset) \ VCL_VOID \ VRT_l_bereq_##which(VRT_CTX, VCL_DURATION num) \ { \ @@ -404,12 +416,14 @@ VRT_r_bereq_##which(VRT_CTX) \ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \ CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC); \ return (ctx->bo->which); \ -} +} \ + \ +BEREQ_TIMEOUT_UNSET##unset(which) -BEREQ_TIMEOUT(connect_timeout) -BEREQ_TIMEOUT(first_byte_timeout) -BEREQ_TIMEOUT(between_bytes_timeout) -BEREQ_TIMEOUT(task_deadline) +BEREQ_TIMEOUT(connect_timeout, 0) +BEREQ_TIMEOUT(first_byte_timeout, 0) +BEREQ_TIMEOUT(between_bytes_timeout, 0) +BEREQ_TIMEOUT(task_deadline, 1) /*--------------------------------------------------------------------*/ diff --git a/bin/varnishtest/tests/s00013.vtc b/bin/varnishtest/tests/s00013.vtc index 2898ec87f..46c7844ba 100644 --- a/bin/varnishtest/tests/s00013.vtc +++ b/bin/varnishtest/tests/s00013.vtc @@ -27,8 +27,9 @@ varnish v1 -cliok "param.set pipe_timeout 0s" varnish v1 -cliok "param.set pipe_task_deadline 0s" varnish v1 -vcl+backend { sub vcl_pipe { - if (req.method == "TMO") { - set bereq.task_deadline = 1.1s; + set bereq.task_deadline = 1.1s; + if (req.method != "TMO") { + unset bereq.task_deadline; } } } -start diff --git a/doc/sphinx/reference/vcl_var.rst b/doc/sphinx/reference/vcl_var.rst index 510d13950..16bb9c8c7 100644 --- a/doc/sphinx/reference/vcl_var.rst +++ b/doc/sphinx/reference/vcl_var.rst @@ -850,8 +850,10 @@ bereq.task_deadline Writable from: vcl_pipe + Unsetable from: vcl_pipe + Deadline for pipe sessions, defaults ``0s``, which falls back to the - ``pipe_task_deadline`` parameter, see :ref:`varnishd(1)` + ``pipe_task_deadline`` parameter, see :ref:`varnishd(1)` .. _bereq.time: From dridi.boukelmoune at gmail.com Mon Feb 5 16:54:06 2024 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 5 Feb 2024 16:54:06 +0000 (UTC) Subject: [master] 8d956aece vtc: Increase stack size for 32bit systems in e29 Message-ID: <20240205165406.3D12B1107E1@lists.varnish-cache.org> commit 8d956aece997e33397f54ed1a22b5102d4805f6c Author: Dridi Boukelmoune Date: Mon Feb 5 17:49:20 2024 +0100 vtc: Increase stack size for 32bit systems in e29 This test case has been failing for a while in continuous integration and trying to bisect the change that triggered a stack overflow for our Ubuntu 18.04 job I wasn't able to make it pass, even for the commit where it first landed. Something must have happened outside of Varnish to consume more stack. diff --git a/bin/varnishtest/tests/e00029.vtc b/bin/varnishtest/tests/e00029.vtc index 556c05cca..e02c78d11 100644 --- a/bin/varnishtest/tests/e00029.vtc +++ b/bin/varnishtest/tests/e00029.vtc @@ -16,7 +16,9 @@ server s1 { chunkedlen 0 } -start -varnish v1 -arg "-p feature=+esi_include_onerror" -vcl+backend { +varnish v1 -cliok "param.set thread_pool_stack 80k" +varnish v1 -cliok "param.set feature +esi_include_onerror" +varnish v1 -vcl+backend { sub vcl_backend_response { set beresp.do_esi = true; set beresp.do_gzip = true; @@ -38,4 +40,4 @@ client c1 { rxresp } -run -logexpect l1 -wait \ No newline at end of file +logexpect l1 -wait From dridi.boukelmoune at gmail.com Mon Feb 5 18:19:04 2024 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 5 Feb 2024 18:19:04 +0000 (UTC) Subject: [master] f383b5c3a vtim: New VTIM_poll_tmo() converter Message-ID: <20240205181904.F40AA1131A0@lists.varnish-cache.org> commit f383b5c3a469f762f0f889aee3c4b918dd1aaf37 Author: Dridi Boukelmoune Date: Thu Feb 1 09:08:56 2024 +0100 vtim: New VTIM_poll_tmo() converter It takes a vtim_dur and returns a number of milliseconds. NAN means no timeout and negative values are considered expired deadlines and get a chance to succeed a non-blocking poll. diff --git a/include/vtim.h b/include/vtim.h index d69a6130d..042feedb1 100644 --- a/include/vtim.h +++ b/include/vtim.h @@ -40,3 +40,4 @@ vtim_real VTIM_real(void); void VTIM_sleep(vtim_dur t); struct timespec VTIM_timespec(vtim_dur t); struct timeval VTIM_timeval(vtim_dur t); +int VTIM_poll_tmo(vtim_dur); diff --git a/lib/libvarnish/vtim.c b/lib/libvarnish/vtim.c index 3918e5eb2..6fdd18245 100644 --- a/lib/libvarnish/vtim.c +++ b/lib/libvarnish/vtim.c @@ -454,6 +454,15 @@ VTIM_timespec(vtim_dur t) return (tv); } +int +VTIM_poll_tmo(vtim_dur tmo) +{ + + if (isnan(tmo)) + return (-1); + return (vmax_t(int, 0, tmo * 1e3)); +} + #ifdef TEST_DRIVER #pragma GCC diagnostic ignored "-Wformat-y2k" From dridi.boukelmoune at gmail.com Mon Feb 5 18:19:05 2024 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 5 Feb 2024 18:19:05 +0000 (UTC) Subject: [master] 33e69f027 vtcp: Use VTIM_poll_tmo() in VTCP_read() Message-ID: <20240205181905.158B61131A3@lists.varnish-cache.org> commit 33e69f0274a5a44327acb71ec644e31d772d2e77 Author: Dridi Boukelmoune Date: Fri Feb 2 19:41:27 2024 +0100 vtcp: Use VTIM_poll_tmo() in VTCP_read() diff --git a/lib/libvarnish/vtcp.c b/lib/libvarnish/vtcp.c index d46142b46..c15dfdedf 100644 --- a/lib/libvarnish/vtcp.c +++ b/lib/libvarnish/vtcp.c @@ -643,10 +643,7 @@ VTCP_read(int fd, void *ptr, size_t len, vtim_dur tmo) pfd[0].fd = fd; pfd[0].events = POLLIN; pfd[0].revents = 0; - j = (int)floor(tmo * 1e3); - if (j == 0) - j++; - j = poll(pfd, 1, j); + j = poll(pfd, 1, VTIM_poll_tmo(tmo)); if (j == 0) return (-2); } From dridi.boukelmoune at gmail.com Mon Feb 5 18:19:05 2024 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 5 Feb 2024 18:19:05 +0000 (UTC) Subject: [master] 17fa38652 v1p: Use VTIM_poll_tmo() Message-ID: <20240205181905.330991131A6@lists.varnish-cache.org> commit 17fa386524b9d6734660f304ef3599611a7e33ab Author: Dridi Boukelmoune Date: Thu Feb 1 09:20:33 2024 +0100 v1p: Use VTIM_poll_tmo() Otherwise poll(2) returns EINVAL on FreeBSD when both pipe_timeout and pipe_task_deadline are disabled. Fixes #4043 diff --git a/bin/varnishd/http1/cache_http1_pipe.c b/bin/varnishd/http1/cache_http1_pipe.c index 7ffe4b68c..98464ab46 100644 --- a/bin/varnishd/http1/cache_http1_pipe.c +++ b/bin/varnishd/http1/cache_http1_pipe.c @@ -149,13 +149,12 @@ V1P_Process(const struct req *req, int fd, struct v1p_acct *v1a, fds[1].revents = 0; tmo = cache_param->pipe_timeout; if (tmo == 0.) - tmo = -1.; + tmo = NAN; if (deadline > 0.) { tmo_task = deadline - VTIM_real(); - tmo = (tmo > 0.) ? vmin(tmo, tmo_task) : tmo_task; - tmo = vmax(tmo, 0.); + tmo = vmin(tmo, tmo_task); } - i = poll(fds, 2, (int)(tmo * 1e3)); + i = poll(fds, 2, VTIM_poll_tmo(tmo)); if (i == 0) sc = SC_RX_TIMEOUT; if (i < 1) From nils.goroll at uplex.de Mon Feb 5 23:44:03 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 5 Feb 2024 23:44:03 +0000 (UTC) Subject: [master] f3575e382 Avoid deadlock in VRT_AddDirector() when VCL is going cold Message-ID: <20240205234404.118DA52E2@lists.varnish-cache.org> commit f3575e382cf00f5cb5a69cbc1f5eb1f42246c87a Author: Nils Goroll Date: Wed Jan 31 09:25:04 2024 +0100 Avoid deadlock in VRT_AddDirector() when VCL is going cold If VRT_AddDirector() was called from handling a VCL_COLD event or, indirectly, from another thread which the VCL_COLD event handler was waiting for, varnishd would deadlock and prevent any CLI or director changes, because VRT_AddDirector() requires the vcl_mtx, which is held during vcl_BackendEvent() to ensure a consistent view of the director list. Because of the early return from VRT_AddDirector() this likely only happened in VTC mode, but the underlying race existed nevertheless. This patch _almost_ fixes the issue with the intend of making it highly unlikely to occur without getting too involved with the vcl temperature controls: We now check the same conditions under which vcl_set_state() would transition the temperature to COOLING and, if they apply, use Lck_Trylock() in a try/wait loop instead of Lck_Lock(), avoiding the deadlock. The patch presumably still does not fix the problem entirely, because the reads of vcl->busy and vcl->temp before the Lck_Trylock() could still be outdated. With the temperature controls otherwise unchanged, the only alternative idea I could come up with was to always use a try/wait loop, which I dismissed due to the performance impact (overhead and added latency). Ref https://github.com/nigoroll/libvmod-dynamic/issues/110 diff --git a/bin/varnishd/cache/cache_vrt_vcl.c b/bin/varnishd/cache/cache_vrt_vcl.c index a454b14d9..82e6e10a5 100644 --- a/bin/varnishd/cache/cache_vrt_vcl.c +++ b/bin/varnishd/cache/cache_vrt_vcl.c @@ -219,8 +219,25 @@ VRT_AddDirector(VRT_CTX, const struct vdi_methods *m, void *priv, * not be legal to do so. Because we change the VCL temperature before * sending COLD events we have to tolerate and undo attempts for the * COOLING case. + * + * To avoid deadlocks during vcl_BackendEvent, we only wait for vcl_mtx + * if the vcl is busy (ref vcl_set_state()) */ - Lck_Lock(&vcl_mtx); + + while (1) { + temp = vcl->temp; + if (temp == VCL_TEMP_COOLING) + return (vcldir_surplus(vdir)); + if (vcl->busy == 0 && vcl->temp->is_warm) { + if (! Lck_Trylock(&vcl_mtx)) + break; + usleep(10 * 1000); + continue; + } + Lck_Lock(&vcl_mtx); + break; + } + Lck_AssertHeld(&vcl_mtx); temp = vcl->temp; if (temp != VCL_TEMP_COOLING) VTAILQ_INSERT_TAIL(&vcl->director_list, vdir, list); From dridi.boukelmoune at gmail.com Wed Feb 7 08:24:07 2024 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Wed, 7 Feb 2024 08:24:07 +0000 (UTC) Subject: [master] 1e03c7b93 varnishncsa: Add %{Varnish:default_format}x Message-ID: <20240207082407.ED3271119BD@lists.varnish-cache.org> commit 1e03c7b938bcef71559467888a27bf990f482433 Author: Walid Boudebouda Date: Tue Jan 30 15:33:41 2024 +0100 varnishncsa: Add %{Varnish:default_format}x This is an extended variable that has the same format as the default one used when no format is specified. The variable is useful for appending or prepending other formatters to the default format. diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c index 0ad6a8708..8789adbe7 100644 --- a/bin/varnishncsa/varnishncsa.c +++ b/bin/varnishncsa/varnishncsa.c @@ -162,6 +162,8 @@ static struct ctx { int64_t vxid; } CTX; +static void parse_format(const char *format); + static void openout(int append) { @@ -681,6 +683,10 @@ parse_x_format(char *buf) addf_vsl((enum VSL_tag_e)slt, lval, r); return; } + if (!strcmp(buf, "Varnish:default_format")) { + parse_format(FORMAT); + return; + } VUT_Error(vut, 1, "Unknown formatting extension: %s", buf); } diff --git a/bin/varnishtest/tests/u00003.vtc b/bin/varnishtest/tests/u00003.vtc index 197ee8919..2f6cc7569 100644 --- a/bin/varnishtest/tests/u00003.vtc +++ b/bin/varnishtest/tests/u00003.vtc @@ -182,4 +182,14 @@ shell -expect ${localhost} { varnishncsa -n ${v1_name} -d -q 'RespStatus == 400' } +shell { + ( + varnishncsa -n ${v1_name} -d -k 1 + varnishncsa -n ${v1_name} -d -k 1 -F "%{User-Agent}i" + ) >def_then_ua.txt + varnishncsa -n ${v1_name} -d -k 1 >def_with_ua.txt \ + -F "%{Varnish:default_format}x\n%{User-Agent}i" + diff -u def_then_ua.txt def_with_ua.txt +} + # ESI coverage in e00003.vtc diff --git a/doc/sphinx/reference/varnishncsa.rst b/doc/sphinx/reference/varnishncsa.rst index 173ea8a63..dc09410f7 100644 --- a/doc/sphinx/reference/varnishncsa.rst +++ b/doc/sphinx/reference/varnishncsa.rst @@ -173,6 +173,10 @@ Supported formatters are: %{X}x Extended variables. Supported variables are: + Varnish:default_format + The log format used when neither -f nor -F options are specified. + Useful for appending/prepending with other formatters. + Varnish:time_firstbyte Time from when the request processing starts until the first byte is sent to the client, in seconds. For backend mode: Time From phk at FreeBSD.org Wed Feb 7 11:41:05 2024 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 7 Feb 2024 11:41:05 +0000 (UTC) Subject: [master] f0dc9964e Implement "include file ..." command Message-ID: <20240207114105.6C55911798E@lists.varnish-cache.org> commit f0dc9964e953fbcc11869957f11382098be0a9ab Author: Poul-Henning Kamp Date: Wed Feb 7 11:22:05 2024 +0000 Implement "include file ..." command Submitted by: @AlveElde in Vtest repo on github diff --git a/bin/varnishtest/cmds.h b/bin/varnishtest/cmds.h index dfc097570..3b8a9e9fd 100644 --- a/bin/varnishtest/cmds.h +++ b/bin/varnishtest/cmds.h @@ -37,6 +37,7 @@ CMD_GLOBAL(barrier) CMD_GLOBAL(delay) CMD_GLOBAL(shell) +CMD_GLOBAL(include) #undef CMD_GLOBAL #ifndef CMD_TOP diff --git a/bin/varnishtest/vtc_misc.c b/bin/varnishtest/vtc_misc.c index 30784d61a..95d4387ee 100644 --- a/bin/varnishtest/vtc_misc.c +++ b/bin/varnishtest/vtc_misc.c @@ -48,6 +48,7 @@ #include "vtc.h" +#include "vfil.h" #include "vnum.h" #include "vre.h" #include "vtcp.h" @@ -349,6 +350,40 @@ cmd_delay(CMD_ARGS) VTIM_sleep(f); } +/* SECTION: include include + * + * Executes a vtc fragment:: + * + * include FILE [...] + * + * Open a file and execute it as a VTC fragment. This command is available + * everywhere commands are given. + * + */ +void +cmd_include(CMD_ARGS) +{ + char *spec; + unsigned i; + + if (av == NULL) + return; + + if (av[1] == NULL) + vtc_fatal(vl, "CMD include: At least 1 argument required"); + + for (i = 1; av[i] != NULL; i++) { + spec = VFIL_readfile(NULL, av[i], NULL); + if (spec == NULL) + vtc_fatal(vl, "CMD include: Unable to read file '%s' " + "(%s)", av[i], strerror(errno)); + vtc_log(vl, 2, "Begin include '%s'", av[i]); + parse_string(vl, priv, spec); + vtc_log(vl, 2, "End include '%s'", av[i]); + free(spec); + } +} + /********************************************************************** * Most test-cases use only numeric IP#'s but a few requires non-demented * DNS services. This is a basic sanity check for those. From dridi.boukelmoune at gmail.com Tue Feb 13 14:58:07 2024 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Tue, 13 Feb 2024 14:58:07 +0000 (UTC) Subject: [master] 7536a4028 vsl_tags: Missing curly bracket in comment Message-ID: <20240213145807.40B11605BF@lists.varnish-cache.org> commit 7536a4028c5bf5fc478ba2651ab4d0dfc6d249b7 Author: Dridi Boukelmoune Date: Tue Feb 13 09:43:34 2024 +0100 vsl_tags: Missing curly bracket in comment diff --git a/include/tbl/vsl_tags.h b/include/tbl/vsl_tags.h index c94af34f2..166d9cf6c 100644 --- a/include/tbl/vsl_tags.h +++ b/include/tbl/vsl_tags.h @@ -100,6 +100,7 @@ SLTM(SessOpen, 0, "Client connection opened", * printf("\t\"\\t* ``%s``: %s\\n\"\n", #e, desc); * #include "include/tbl/sess_close.h" * return (0); + * } */ SLTM(SessClose, 0, "Client connection closed", From dridi.boukelmoune at gmail.com Tue Feb 13 14:58:07 2024 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Tue, 13 Feb 2024 14:58:07 +0000 (UTC) Subject: [master] f364fa300 v1l: restore errno on error Message-ID: <20240213145807.388CB605BC@lists.varnish-cache.org> commit f364fa3008ede474d70c0b35feb2c05b21001388 Author: Dridi Boukelmoune Date: Wed Jan 31 17:35:11 2024 +0100 v1l: restore errno on error Spotted by Darryl Rodden. diff --git a/bin/varnishd/http1/cache_http1_line.c b/bin/varnishd/http1/cache_http1_line.c index 82ae2fe26..b1087d1e6 100644 --- a/bin/varnishd/http1/cache_http1_line.c +++ b/bin/varnishd/http1/cache_http1_line.c @@ -253,6 +253,7 @@ V1L_Flush(const struct worker *wrk) v1l->werr = SC_REM_CLOSE; else v1l->werr = SC_TX_ERROR; + errno = err; } } v1l->liov = 0; From dridi.boukelmoune at gmail.com Tue Feb 13 14:58:07 2024 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Tue, 13 Feb 2024 14:58:07 +0000 (UTC) Subject: [master] 223847ea0 v1f: Log a useful HTC status Message-ID: <20240213145807.74086605C4@lists.varnish-cache.org> commit 223847ea09a0a5440510fe8c383bdac56890dff5 Author: Dridi Boukelmoune Date: Tue Feb 13 15:25:05 2024 +0100 v1f: Log a useful HTC status Instead of adding hoops to the documentation, in particular to keep it in sync, improve the only location where we emit HTC status logs. We could also consider replacing the HTC enum with a struct, similar to what we did in other places. The struct symbols would be named after the UPPER name from the table, have a name and description fields, possibly replace the error number with a simple is_err field. Capturing the long description like this is less intrusive. Refs #4042 diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index dfa2a0bf7..43d5ab60e 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -237,17 +237,20 @@ SES_Get_String_Attr(const struct sess *sp, enum sess_attr a) /*--------------------------------------------------------------------*/ -const char * -HTC_Status(enum htc_status_e e) +void +HTC_Status(enum htc_status_e e, const char **name, const char **desc) { + switch (e) { #define HTC_STATUS(e, n, s, l) \ - case HTC_S_ ## e: return (s); + case HTC_S_ ## e: \ + *name = s; \ + *desc = l; \ + return; #include "tbl/htc.h" default: WRONG("HTC_Status"); } - NEEDLESS(return (NULL)); } /*--------------------------------------------------------------------*/ diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h index 062041f49..540781821 100644 --- a/bin/varnishd/cache/cache_varnishd.h +++ b/bin/varnishd/cache/cache_varnishd.h @@ -436,7 +436,7 @@ void SES_Wait(struct sess *, const struct transport *); void SES_Ref(struct sess *sp); void SES_Rel(struct sess *sp); -const char * HTC_Status(enum htc_status_e); +void HTC_Status(enum htc_status_e, const char **, const char **); void HTC_RxInit(struct http_conn *htc, struct ws *ws); void HTC_RxPipeline(struct http_conn *htc, char *); enum htc_status_e HTC_RxStuff(struct http_conn *, htc_complete_f *, diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c index 05fe46418..1a2ced1e8 100644 --- a/bin/varnishd/http1/cache_http1_fetch.c +++ b/bin/varnishd/http1/cache_http1_fetch.c @@ -175,6 +175,7 @@ V1F_FetchRespHdr(struct busyobj *bo) double t; struct http_conn *htc; enum htc_status_e hs; + const char *name, *desc; CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); CHECK_OBJ_NOTNULL(bo->htc, HTTP_CONN_MAGIC); @@ -219,8 +220,9 @@ V1F_FetchRespHdr(struct busyobj *bo) htc->doclose = SC_RX_TIMEOUT; break; default: - VSLb(bo->vsl, SLT_FetchError, "HTC %s (%d)", - HTC_Status(hs), hs); + HTC_Status(hs, &name, &desc); + VSLb(bo->vsl, SLT_FetchError, "HTC %s (%s)", + name, desc); htc->doclose = SC_RX_BAD; break; } diff --git a/bin/varnishtest/tests/c00036.vtc b/bin/varnishtest/tests/c00036.vtc index 243339a6e..a229b74f0 100644 --- a/bin/varnishtest/tests/c00036.vtc +++ b/bin/varnishtest/tests/c00036.vtc @@ -27,7 +27,7 @@ logexpect l1 -v v1 -q "vxid == 1004" { # purpose of this vtc: test the internal retry when the # backend goes away on a keepalive TCP connection: - expect 0 1004 FetchError {^HTC eof .-1.} + expect 0 1004 FetchError {^HTC eof .Unexpected end of input.} expect 0 1004 BackendClose {^\d+ s1} expect 0 1004 Timestamp {^Connected:} expect 0 1004 BackendOpen {^\d+ s1} diff --git a/include/tbl/vsl_tags.h b/include/tbl/vsl_tags.h index 166d9cf6c..378916cab 100644 --- a/include/tbl/vsl_tags.h +++ b/include/tbl/vsl_tags.h @@ -92,7 +92,7 @@ SLTM(SessOpen, 0, "Client connection opened", "\n" ) /* - * XXX generate the list of SC_* reasons (see also HTC info): + * XXX generate the list of SC_* reasons: * * #include * int main(void) { @@ -189,33 +189,9 @@ SLTM(Length, 0, "Size of object body", "Logs the size of a fetch object body.\n\n" ) -/* - * XXX generate HTC info below from tbl include - * - * #include - * int main(void) { - * #define HTC_STATUS(e, n, s, l) \ - * printf("\t\"\\t* ``%s`` (%d): %s\\n\"\n", s, n, l); - * #include "include/tbl/htc.h" - * return (0); - * } - */ - SLTM(FetchError, 0, "Error while fetching object", "Logs the error message of a failed fetch operation.\n\n" - "Error messages should be self-explanatory, yet the http connection\n" - "(HTC) class of errors is reported with these symbols:\n\n" - "\t* ``junk`` (-5): Received unexpected data\n" - "\t* ``close`` (-4): Connection closed\n" - "\t* ``timeout`` (-3): Timed out\n" - "\t* ``overflow`` (-2): Buffer/workspace too small\n" - "\t* ``eof`` (-1): Unexpected end of input\n" - "\t* ``empty`` (0): Empty response\n" - "\t* ``more`` (1): More data required\n" - "\t* ``complete`` (2): Data complete (no error)\n" - "\t* ``idle`` (3): Connection was closed while idle\n" - "\nNotice that some HTC errors are never emitted." - ) +) #define SLTH(tag, ind, req, resp, sdesc, ldesc) \ SLTM(Req##tag, (req ? 0 : SLT_F_UNUSED), "Client request " sdesc, ldesc) From dridi.boukelmoune at gmail.com Thu Feb 15 11:30:10 2024 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Thu, 15 Feb 2024 11:30:10 +0000 (UTC) Subject: [master] 88d927a23 req_fsm: Avoid misleading Timestamp:Process Message-ID: <20240215113010.91302101AA5@lists.varnish-cache.org> commit 88d927a23e815368a48147c37fab64fa587a40ca Author: Stephane Cance Date: Wed Feb 7 16:35:32 2024 +0100 req_fsm: Avoid misleading Timestamp:Process When `vcl_deliver` does not return `deliver` the timestamp ends up being a duplicate of the `synth` equivalent or the `restart` timestamp. diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c index 3f92d91aa..e84407647 100644 --- a/bin/varnishd/cache/cache_req_fsm.c +++ b/bin/varnishd/cache/cache_req_fsm.c @@ -233,8 +233,6 @@ cnt_deliver(struct worker *wrk, struct req *req) req->t_resp = W_TIM_real(wrk); VCL_deliver_method(req->vcl, wrk, req, NULL, NULL); - VSLb_ts_req(req, "Process", W_TIM_real(wrk)); - assert(req->restarts <= cache_param->max_restarts); if (wrk->vpi->handling != VCL_RET_DELIVER) { @@ -259,6 +257,8 @@ cnt_deliver(struct worker *wrk, struct req *req) return (REQ_FSM_MORE); } + VSLb_ts_req(req, "Process", W_TIM_real(wrk)); + assert(wrk->vpi->handling == VCL_RET_DELIVER); if (IS_TOPREQ(req) && RFC2616_Do_Cond(req)) diff --git a/bin/varnishtest/tests/s00004.vtc b/bin/varnishtest/tests/s00004.vtc index d86903f7c..36775d1d2 100644 --- a/bin/varnishtest/tests/s00004.vtc +++ b/bin/varnishtest/tests/s00004.vtc @@ -30,7 +30,6 @@ logexpect l1 -v v1 -g request { expect * = Timestamp {Start: \S+ 0\.000000 0\.000000} expect * = Timestamp {Req: \S+ 0\.\d+ 0\.\d+} expect * = Timestamp {Fetch: \S+ [0-4]\.\d+ [0-4]\.\d+} - expect * = Timestamp {Process: \S+ 2\.\d+ 0\.\d+} expect * = Timestamp {Restart: \S+ 2\.\d+ 0\.\d+} expect * = End expect 0 1002 Begin bereq From dridi.boukelmoune at gmail.com Thu Feb 15 11:30:10 2024 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Thu, 15 Feb 2024 11:30:10 +0000 (UTC) Subject: [master] 43af86cc4 lck: Mention why we expect EINTR for a cond wait Message-ID: <20240215113010.A98EF101AA9@lists.varnish-cache.org> commit 43af86cc40ed78a4b41be60fa3542e45ad644285 Author: Dridi Boukelmoune Date: Thu Feb 15 12:28:08 2024 +0100 lck: Mention why we expect EINTR for a cond wait diff --git a/bin/varnishd/cache/cache_lck.c b/bin/varnishd/cache/cache_lck.c index ee3d9a473..8f33dee8c 100644 --- a/bin/varnishd/cache/cache_lck.c +++ b/bin/varnishd/cache/cache_lck.c @@ -271,6 +271,9 @@ Lck_CondWaitUntil(pthread_cond_t *cond, struct lock *lck, vtim_real when) errno = pthread_cond_timedwait(cond, &ilck->mtx, &ts); } #endif + /* We should never observe EINTR, but we have in the past. For + * example when sanitizers are enabled. + */ assert(errno == 0 || errno == ETIMEDOUT || errno == EINTR); From dridi at varni.sh Thu Feb 15 11:36:48 2024 From: dridi at varni.sh (Dridi Boukelmoune) Date: Thu, 15 Feb 2024 11:36:48 +0000 Subject: [master] 88d927a23 req_fsm: Avoid misleading Timestamp:Process In-Reply-To: <20240215113010.91302101AA5@lists.varnish-cache.org> References: <20240215113010.91302101AA5@lists.varnish-cache.org> Message-ID: On Thu, Feb 15, 2024 at 11:30?AM Dridi Boukelmoune wrote: > > > commit 88d927a23e815368a48147c37fab64fa587a40ca > Author: Stephane Cance > Date: Wed Feb 7 16:35:32 2024 +0100 > > req_fsm: Avoid misleading Timestamp:Process > > When `vcl_deliver` does not return `deliver` the timestamp ends > up being a duplicate of the `synth` equivalent or the `restart` > timestamp. St?phane who authored this change is also working on more extensive coverage of our timestamps. That's how we found that return(synth) from vcl_deliver results in two Process timestamps. We will submit the aforementioned coverage separately since it is still work in progress (trying to find missing or undesirable timestamps for a fair amount of VCL paths). Dridi > diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c > index 3f92d91aa..e84407647 100644 > --- a/bin/varnishd/cache/cache_req_fsm.c > +++ b/bin/varnishd/cache/cache_req_fsm.c > @@ -233,8 +233,6 @@ cnt_deliver(struct worker *wrk, struct req *req) > req->t_resp = W_TIM_real(wrk); > VCL_deliver_method(req->vcl, wrk, req, NULL, NULL); > > - VSLb_ts_req(req, "Process", W_TIM_real(wrk)); > - > assert(req->restarts <= cache_param->max_restarts); > > if (wrk->vpi->handling != VCL_RET_DELIVER) { > @@ -259,6 +257,8 @@ cnt_deliver(struct worker *wrk, struct req *req) > return (REQ_FSM_MORE); > } > > + VSLb_ts_req(req, "Process", W_TIM_real(wrk)); > + > assert(wrk->vpi->handling == VCL_RET_DELIVER); > > if (IS_TOPREQ(req) && RFC2616_Do_Cond(req)) > diff --git a/bin/varnishtest/tests/s00004.vtc b/bin/varnishtest/tests/s00004.vtc > index d86903f7c..36775d1d2 100644 > --- a/bin/varnishtest/tests/s00004.vtc > +++ b/bin/varnishtest/tests/s00004.vtc > @@ -30,7 +30,6 @@ logexpect l1 -v v1 -g request { > expect * = Timestamp {Start: \S+ 0\.000000 0\.000000} > expect * = Timestamp {Req: \S+ 0\.\d+ 0\.\d+} > expect * = Timestamp {Fetch: \S+ [0-4]\.\d+ [0-4]\.\d+} > - expect * = Timestamp {Process: \S+ 2\.\d+ 0\.\d+} > expect * = Timestamp {Restart: \S+ 2\.\d+ 0\.\d+} > expect * = End > expect 0 1002 Begin bereq > _______________________________________________ > varnish-commit mailing list > varnish-commit at varnish-cache.org > https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit From phk at FreeBSD.org Mon Feb 19 08:25:09 2024 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 19 Feb 2024 08:25:09 +0000 (UTC) Subject: [master] 2921ac509 Flexelinting Message-ID: <20240219082509.CD205117990@lists.varnish-cache.org> commit 2921ac509cfbc6ca914e88ef682122691eb8f048 Author: Poul-Henning Kamp Date: Mon Feb 19 08:24:11 2024 +0000 Flexelinting diff --git a/lib/libvarnish/vtim.c b/lib/libvarnish/vtim.c index 6fdd18245..01e218db5 100644 --- a/lib/libvarnish/vtim.c +++ b/lib/libvarnish/vtim.c @@ -460,7 +460,7 @@ VTIM_poll_tmo(vtim_dur tmo) if (isnan(tmo)) return (-1); - return (vmax_t(int, 0, tmo * 1e3)); + return (vmax_t(int, 0, ((int)(tmo * 1e3)))); } #ifdef TEST_DRIVER From nils.goroll at uplex.de Mon Feb 19 11:47:05 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 19 Feb 2024 11:47:05 +0000 (UTC) Subject: [master] 8cbb4d1e6 varnishd: kill the killlist Message-ID: <20240219114706.00A0B11DA58@lists.varnish-cache.org> commit 8cbb4d1e671b8070a55822f20b95a8f6790f17d8 Author: Asad Sajjad Ahmed Date: Mon Feb 19 11:47:43 2024 +0100 varnishd: kill the killlist Since, we seems to not use it at all. Signed-off-by: Asad Sajjad Ahmed diff --git a/bin/varnishd/cache/cache_conn_pool.c b/bin/varnishd/cache/cache_conn_pool.c index 438082c16..131fc20da 100644 --- a/bin/varnishd/cache/cache_conn_pool.c +++ b/bin/varnishd/cache/cache_conn_pool.c @@ -95,7 +95,6 @@ struct conn_pool { VTAILQ_HEAD(, pfd) connlist; int n_conn; - VTAILQ_HEAD(, pfd) killlist; int n_kill; int n_used; @@ -180,7 +179,6 @@ vcp_handle(struct waited *w, enum wait_event ev, vtim_real now) case PFD_STATE_CLEANUP: cp->methods->close(pfd); cp->n_kill--; - VTAILQ_REMOVE(&cp->killlist, pfd, list); memset(pfd, 0x11, sizeof *pfd); free(pfd); break; @@ -234,7 +232,6 @@ VCP_Rel(struct conn_pool **cpp) assert(pfd->state == PFD_STATE_AVAIL); pfd->state = PFD_STATE_CLEANUP; (void)shutdown(pfd->fd, SHUT_WR); - VTAILQ_INSERT_TAIL(&cp->killlist, pfd, list); cp->n_kill++; } while (cp->n_kill) { @@ -419,7 +416,6 @@ VCP_Close(struct pfd **pfdp) (void)shutdown(pfd->fd, SHUT_RDWR); VTAILQ_REMOVE(&cp->connlist, pfd, list); pfd->state = PFD_STATE_CLEANUP; - VTAILQ_INSERT_HEAD(&cp->killlist, pfd, list); cp->n_kill++; } else { assert(pfd->state == PFD_STATE_USED); @@ -738,7 +734,6 @@ VCP_Ref(const struct vrt_endpoint *vep, const char *ident) cp->methods = &vtp_methods; Lck_New(&cp->mtx, lck_conn_pool); VTAILQ_INIT(&cp->connlist); - VTAILQ_INIT(&cp->killlist); CHECK_OBJ_NOTNULL(cp, CONN_POOL_MAGIC); Lck_Lock(&conn_pools_mtx); From nils.goroll at uplex.de Mon Feb 19 11:52:05 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 19 Feb 2024 11:52:05 +0000 (UTC) Subject: [master] d77da13b9 Move decision on fetch_chunksize to the storage engine Message-ID: <20240219115205.31B1311DE04@lists.varnish-cache.org> commit d77da13b9baf268196075bda0808d0d2e8721470 Author: Nils Goroll Date: Wed Feb 14 19:28:24 2024 +0100 Move decision on fetch_chunksize to the storage engine For chunked encoding, we do not know how big the object is ultimately going to be, so VFP_GetStorage() called ObjGetSpace() with the fetch_chunksize parameter in this case. Yet which size is best might differ for different storage engines, and having the information that the caller does not know the final size might be relevant. Storage engines could guess that if a request came in for fetch_chunksize that this _might_ be the "chunked" case, but that heuristic would be wrong for Objects of just that size advertised via Content-Length. So this patch takes the guesswork out of the game by just passing the magic 0 value down to the storage engine to mean "give me some good chunk of bytes, I do not know how much I am going to need". diff --git a/bin/varnishd/cache/cache_fetch_proc.c b/bin/varnishd/cache/cache_fetch_proc.c index 150b473f9..704262b60 100644 --- a/bin/varnishd/cache/cache_fetch_proc.c +++ b/bin/varnishd/cache/cache_fetch_proc.c @@ -71,19 +71,15 @@ VFP_Error(struct vfp_ctx *vc, const char *fmt, ...) enum vfp_status VFP_GetStorage(struct vfp_ctx *vc, ssize_t *sz, uint8_t **ptr) { - ssize_t l; CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC); AN(sz); assert(*sz >= 0); AN(ptr); - l = fetchfrag; - if (l == 0) - l = *sz; - if (l == 0) - l = cache_param->fetch_chunksize; - *sz = l; + if (fetchfrag > 0) + *sz = fetchfrag; + if (!ObjGetSpace(vc->wrk, vc->oc, sz, ptr)) { *sz = 0; *ptr = NULL; diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c index 2ff54cb8e..ec819bf8c 100644 --- a/bin/varnishd/cache/cache_obj.c +++ b/bin/varnishd/cache/cache_obj.c @@ -190,6 +190,7 @@ ObjIterate(struct worker *wrk, struct objcore *oc, * is no free space, some will be added first. * * The "sz" argument is an input hint of how much space is desired. + * 0 means "unknown", return some default size (maybe fetch_chunksize) */ int @@ -201,7 +202,7 @@ ObjGetSpace(struct worker *wrk, struct objcore *oc, ssize_t *sz, uint8_t **ptr) CHECK_OBJ_NOTNULL(oc->boc, BOC_MAGIC); AN(sz); AN(ptr); - assert(*sz > 0); + assert(*sz >= 0); AN(om->objgetspace); return (om->objgetspace(wrk, oc, sz, ptr)); diff --git a/bin/varnishd/storage/storage_debug.c b/bin/varnishd/storage/storage_debug.c index 290606ba6..f2500d8ed 100644 --- a/bin/varnishd/storage/storage_debug.c +++ b/bin/varnishd/storage/storage_debug.c @@ -57,7 +57,7 @@ smd_lsp_getspace(struct worker *wrk, struct objcore *oc, ssize_t *sz, uint8_t **ptr) { AN(sz); - if (*sz > 1) + if (*sz > 2) (*sz)--; return (SML_methods.objgetspace(wrk, oc, sz, ptr)); } diff --git a/bin/varnishd/storage/storage_simple.c b/bin/varnishd/storage/storage_simple.c index c34f6e394..c92304593 100644 --- a/bin/varnishd/storage/storage_simple.c +++ b/bin/varnishd/storage/storage_simple.c @@ -476,6 +476,8 @@ sml_getspace(struct worker *wrk, struct objcore *oc, ssize_t *sz, CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); AN(sz); AN(ptr); + if (*sz == 0) + *sz = cache_param->fetch_chunksize; assert(*sz > 0); o = sml_getobj(wrk, oc); From nils.goroll at uplex.de Mon Feb 26 10:27:08 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 26 Feb 2024 10:27:08 +0000 (UTC) Subject: [master] ce6ea4079 Add missing comma to wflags.py Message-ID: <20240226102708.54B406262E@lists.varnish-cache.org> commit ce6ea4079c0cf49b106fc44497b460ed0edb3153 Author: Steven Wojcik Date: Fri Feb 23 10:02:25 2024 -0500 Add missing comma to wflags.py diff --git a/wflags.py b/wflags.py index 1b8c48fc0..10cfd68fd 100644 --- a/wflags.py +++ b/wflags.py @@ -69,7 +69,7 @@ DESIRABLE_WFLAGS = [ ] UNDESIRABLE_WFLAGS = [ - "-Wno-system-headers" # Outside of our control + "-Wno-system-headers", # Outside of our control "-Wno-thread-safety", # Does not understand our mutexs are wrapped "-Wno-old-style-definition", # Does not like vgz "-Wno-sign-compare", # Fixable From nils.goroll at uplex.de Mon Feb 26 14:20:07 2024 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 26 Feb 2024 14:20:07 +0000 (UTC) Subject: [master] 1d4950a3c Fix build order of BUILD_VMOD_$NAME m4 macro Message-ID: <20240226142007.CB6AB103C11@lists.varnish-cache.org> commit 1d4950a3c93a0bd86d4be0d583dcf5a969950858 Author: Steven Wojcik Date: Fri Feb 23 10:08:16 2024 -0500 Fix build order of BUILD_VMOD_$NAME m4 macro When a VMOD adds a CFLAG with `libvmod_$1_la_CFLAGS` the object name is no longer `vmod_$name.lo` but `$library-vmod_name.lo` this changes the build order such that the VCC autogenerated files would not be guaranteed to compile first causing compilation issues. diff --git a/varnish.m4 b/varnish.m4 index 80846579c..e7e596717 100644 --- a/varnish.m4 +++ b/varnish.m4 @@ -213,9 +213,9 @@ AC_DEFUN([_VARNISH_VMOD], [ AC_SUBST(m4_toupper(BUILD_VMOD_$1), [" -vmod_$1.lo: vcc_$1_if.c vcc_$1_if.h +\$(libvmod_$1_la_OBJECTS): vcc_$1_if.c vcc_$1_if.h -vmod_$1.lo: \$(nodist_libvmod_$1_la_SOURCES) +\$(libvmod_$1_la_OBJECTS): \$(nodist_libvmod_$1_la_SOURCES) vcc_$1_if.h vmod_$1.rst vmod_$1.man.rst: vcc_$1_if.c From dridi.boukelmoune at gmail.com Wed Feb 28 14:02:05 2024 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Wed, 28 Feb 2024 14:02:05 +0000 (UTC) Subject: [master] 3eeb8c4f5 vtc: Coverage for withdrawn bgfetch Message-ID: <20240228140205.C429E113BB1@lists.varnish-cache.org> commit 3eeb8c4f5014e2abcbc87292b876f40b0b1f09e8 Author: Dridi Boukelmoune Date: Wed Feb 28 14:54:09 2024 +0100 vtc: Coverage for withdrawn bgfetch This adds coverage for a non-delivery transition from vcl_hit, where the busy objcore would drop its sole reference in the event of a grace hit. The lack of coverage was visible in the gcov dashboard: 669 580 if (busy != NULL) { 670 0 (void)HSH_DerefObjCore(wrk, &busy, 0); 671 0 VRY_Clear(req); 672 0 } There should now be at least one pass inside this block. Refs #4032 diff --git a/bin/varnishtest/tests/c00128.vtc b/bin/varnishtest/tests/c00128.vtc new file mode 100644 index 000000000..e39b1a9cf --- /dev/null +++ b/bin/varnishtest/tests/c00128.vtc @@ -0,0 +1,29 @@ +varnishtest "Withdraw graced hit's busy objcore" + +server s1 { + rxreq + txresp +} -start + +varnish v1 -vcl+backend { + sub vcl_backend_response { + set beresp.ttl = 1ms; + } + sub vcl_hit { + if (obj.ttl < 0s) { + return (fail); + } + } +} -start + +client c1 { + txreq + rxresp + expect resp.status == 200 + + delay 0.01 + + txreq + rxresp + expect resp.status == 503 +} -run