-
Nils Goroll authored
This commit adds the final bit to fix #2902: As discussed in the ticket, there should be no VRT_CTX msg vsb present for COLD events, yet existing code did provide it in some cases. This commit message comments on changes in cache_vcl.c in order of appearance. Existing code kept the CLI VRT_CTX around for longer than it strictly needed to just because access to the error message in ctx->msg was still required. In order to be able to simplify management of the CLI VRT_CTX, we change VCL_Rel_CliCtx() to return the ctx->msg IFF it was requested by a true argument to VCL_Get_CliCtx() Regarding #2902, the main issue with existing code was that the decision on whether or not to request a ctx->msg was separated from where we could actually make that decision: It is (only) in vcl_send_event() where we know which event is going to be issued, which, in turn, determines if we are going to need a ctx->msg. Thus, we move the VRT_CTX management for all of the CLI operations into one place in vcl_send_event() and change the infrastructure around it to handle the vcl and the error message vsb instead of a VRT_CTX. This allows us to (finally) ensure that VCL_EVENT_COLD does never have a ctx->msg error vsb, asserted by AZ(havemsg) in the switch/case statement in vcl_send_event(). In vcl_send_event(), we also assert that if a vcl subroutine was called in the case of a LOAD or DISCARD event, only vcl_init {} for a LOAD event may return anything but OK. vcl_set_state() contains the two use cases of vcl_send_event(): When we know that an event may not fail, we also assert that there is no msg vsb returned, and if it could, we keep it, as it is still required by its callers. vcl_cancel_load() shows how the new infrastructure simplifies the code: Rather than having to re-setup the VRT_CTX for the DISCARD event, we simply output the error and have vcl_send_event() set up the proper handling for that event. Basically the same pattern repeats in vcl_load(), VCL_Poll() and vcl_cli_state(): In these functions, we only look after error handling and output. Fixes #2902