[Varnish] #1800: PRIV_TASK in a vmod object method leads to code that cannot be compiled/linked
Varnish
varnish-bugs at varnish-cache.org
Sun Oct 11 21:00:20 CEST 2015
#1800: PRIV_TASK in a vmod object method leads to code that cannot be
compiled/linked
-------------------+--------------------
Reporter: geoff | Type: defect
Status: new | Priority: normal
Milestone: Later | Component: vmod
Version: 4.1.0 | Severity: normal
Keywords: |
-------------------+--------------------
This diff in the vcc declaration of vmod_debug:
{{{
diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc
index dad36ec..9dd9f5b 100644
--- a/lib/libvmod_debug/vmod.vcc
+++ b/lib/libvmod_debug/vmod.vcc
@@ -89,6 +89,8 @@ $Method TIME .date()
You never know when you need a date.
+$Method VOID .task(PRIV_TASK)
+
$Function VOID rot52(HTTP hdr)
Encrypt the HTTP header with quad-ROT13 encryption,
}}}
... causes about 25 vtc tests to fail, all of them with this error
message:
{{{
**** v1 0.2 CLI RX| Message from VCC-compiler:\n
**** v1 0.2 CLI RX| Could not load VMOD debug\n
**** v1 0.2 CLI RX| \tFile name: /home/geoff/Develop/varnish/varnish-
cache/lib/libvmod_debug/.libs/libvmod_debug.so\n
**** v1 0.2 CLI RX| \tdlerror:: /home/geoff/Develop/varnish/varnish-
cache/lib/libvmod_debug/.libs/libvmod_debug.so: undefined symbol:
vmod_obj_task\n
**** v1 0.2 CLI RX| ('input' Line 5 Pos 16)\n
**** v1 0.2 CLI RX| import debug from
"/home/geoff/Develop/varnish/varnish-
cache/lib/libvmod_debug/.libs/libvmod_debug.so";\n
**** v1 0.2 CLI RX|
---------------#####-------------------------------------------------------------------------------------------\n
**** v1 0.2 CLI RX| \n
**** v1 0.2 CLI RX| Running VCC-compiler failed, exited with 2\n
**** v1 0.2 CLI RX| VCL compilation failed
---- v1 0.2 FAIL VCL does not compile
}}}
In my own VMOD I'm getting a compile error for the C code generated for
the VMOD:
{{{
**** v1 0.3 CLI RX| Message from C-compiler:\n
**** v1 0.3 CLI RX| vgc.c: In function
\xe2\x80\x98VGC_function_vcl_backend_response\xe2\x80\x99:\n
**** v1 0.3 CLI RX| vgc.c:1178:31: error:
\xe2\x80\x98VGC_vmod_bar\xe2\x80\x99 undeclared (first use in this
function)\n
**** v1 0.3 CLI RX| VRT_priv_task(ctx, &VGC_vmod_bar),\n
**** v1 0.3 CLI RX| ^\n
**** v1 0.3 CLI RX| vgc.c:1178:31: note: each undeclared identifier is
reported only once for each function it appears in\n
**** v1 0.3 CLI RX| vgc.c: In function
\xe2\x80\x98VGC_function_vcl_recv\xe2\x80\x99:\n
**** v1 0.3 CLI RX| vgc.c:1429:31: error:
\xe2\x80\x98VGC_vmod_foobar\xe2\x80\x99 undeclared (first use in this
function)\n
**** v1 0.3 CLI RX| VRT_priv_task(ctx, &VGC_vmod_foobar),\n
**** v1 0.3 CLI RX| ^\n
**** v1 0.3 CLI RX| vgc.c:1439:31: error:
\xe2\x80\x98VGC_vmod_snafu\xe2\x80\x99 undeclared (first use in this
function)\n
**** v1 0.3 CLI RX| [2 lines truncated]\n
**** v1 0.3 CLI RX| Running C-compiler failed, exited with 1\n
**** v1 0.3 CLI RX| VCL compilation failed
---- v1 0.3 FAIL VCL does not compile
}}}
The vmodtool doesn't throw any errors, but the generated code is
defective. Evidently a symbol is generated for the private object that is
not declared.
The use case is a VMOD object that is intended to have state across method
calls within a "task" (client or backend context). In my case, it's for a
regex VMOD with a backref call meant to refer back to captured expressions
in a previous match call (https://code.uplex.de/uplex-varnish/libvmod-re).
The VCC interface is something like this:
{{{
$Object regex(STRING)
$Method BOOL .match(PRIV_TASK, STRING)
$Method STRING .backref(PRIV_TASK, INT)
}}}
With usage like this:
{{{
import re;
sub vcl_init {
# compile a regex
new myregex = re.regex("foo(bar)");
}
sub vcl_recv {
if (myregex.match(req.http.Foo)) {
set req.http.Bar = myregex.backref(1);
}
}}}
The immediate defect is that code is generated that either can't be
compiled or linked. More generally, it seems very intuitive to me that
object methods should be able to maintain a state with task scope -- the
regex example is basic stuff. Up to now, I'd been maintaining state by
using pthread-local keys, but I thought using PRIV_TASK would be the more
natural, Varnishy solution.
--
Ticket URL: <https://www.varnish-cache.org/trac/ticket/1800>
Varnish <https://varnish-cache.org/>
The Varnish HTTP Accelerator
More information about the varnish-bugs
mailing list