<div dir="ltr">Hi Lee,<div><br></div><div>Looks like you had the right page, but missed the interesting part :-) In you <a href="https://varnish-cache.org/docs/trunk/reference/vmod.html#ref-vmod-private-pointers">https://varnish-cache.org/docs/trunk/reference/vmod.html#ref-vmod-private-pointers</a> have this bit:</div><div><br></div><div>> .fini will be called for a non-NULL .priv of the struct vmod_priv when the scope ends with that .priv pointer as its second argument besides a VRT_CTX.</div><div><br></div><div>i.e. if your <span style="background-color:unset">vmod_priv has a methods->fini pointer, it will be called when the vmod_priv is deleted.</span></div><div><span style="background-color:unset"><br></span></div><div><span style="background-color:unset">Was this what you were after, or did I misunderstand your question?</span></div><div><span style="background-color:unset"><br></span></div><div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>-- <br></div><div>Guillaume Quintard<br></div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Mar 23, 2022 at 7:28 AM Lee Hambley <<a href="mailto:lee.hambley@gmail.com">lee.hambley@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Dear List,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">I inherited a project using PRIV_TASK [1] for which the documentation says:<br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;margin-left:40px"><code><span>PRIV_TASK</span></code> “per task” private pointers are useful for state that
applies to calls for either a specific request or a backend
request. For instance this can be the result of a parsed cookie
specific to a client. Note that <code><span>PRIV_TASK</span></code> contexts are separate
for the client side and the backend side, so use in
<code><span>vcl_backend_*</span></code> will yield a different private pointer from the
one used on the client side.
These private pointers live only for the duration of their task.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">We
 do a form of reference counting in our internal data structures, and 
the PRIV_TASK pointer in parts is used to hold a (counted) reference to 
some data in the shared structure. <br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">We
 are struggling to find the latest possible safest place to hook where 
PRIV_TASK is about to be invalid (end of the request) so that we can 
safely, and finally decrement the reference count and clean-up.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Writing
 this out now, I suspect that there's a safe exit from the state machine
 [2] where we could modify our VCL to include a call to a clean-up 
function in our vmod, however it's not clear to me if this would be 
"safe" (restarts, request coalescing, etc, etc)</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">In
 short then, is there an obvious place into which we can hook which is 
the place where Varnish is already about to discard the "task" and it is
 unoquivically safe for us to decrement our reference counted pointer to
 the PRIV_TASK referenced data?<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Thanks so much, very much enjoying being in a role hacking on Varnish, and Varnish adjacent stuff in my job currently.<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">[1]: <a href="https://varnish-cache.org/docs/trunk/reference/vmod.html#ref-vmod-private-pointers" target="_blank">https://varnish-cache.org/docs/trunk/reference/vmod.html#ref-vmod-private-pointers</a></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">[2]: <a href="https://www.varnish-software.com/developers/tutorials/varnish-configuration-language-vcl/#finite-state-machine" target="_blank">https://www.varnish-software.com/developers/tutorials/varnish-configuration-language-vcl/#finite-state-machine</a></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br clear="all"><br></div></div><div><div dir="ltr"><div dir="ltr"><div>Lee Hambley<div><a href="http://lee.hambley.name/" target="_blank">http://lee.hambley.name/</a><br></div><div>+49 (0) 170 298 5667</div></div></div></div></div></div>
_______________________________________________<br>
varnish-misc mailing list<br>
<a href="mailto:varnish-misc@varnish-cache.org" target="_blank">varnish-misc@varnish-cache.org</a><br>
<a href="https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc" rel="noreferrer" target="_blank">https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc</a><br>
</blockquote></div>