BUG/MEDIUM: applets: do not wake up applets before the end of the request analysis
The applet is woken up as soon as it is created by sc_applet_create(). But
the request analysis is not over at this point and it may still be paused,
typically by a "http-request wait-for-body" rule, while the applet is
already attached to the back stream connector (the cache after a
cache-use hit, for instance). Thus, the applet could start to consume the
request and to produce its response before the end of the request
analysis, and the response analysers were evaluated in the same time. It
is unexpected and it could lead to weird issues.
To fix the issue, the way the applets are created is changed.
sc_applet_create() no longer schedules the applet and it no longer
switches the stream connector to the ready state. The applet remains in
SC_ST_INI state, in a dormant state, and the request analysis can
continue, undisturbed. The applet is woken up by back_handle_st_req(),
when the request analysis is over and the stream connector switches from
SC_ST_INI to SC_ST_REQ and then to SC_ST_RDY.
Thus, process_use_service() was reviewed accordingly. Because the
use-service action is terminal and it never yields, there is no re-entry
in this function, so the re-entry branch was removed. And the applet is
not woken up by the action anymore. It will be done by
back_handle_st_req(). Note that a re-entry would now fail in
sc_applet_create(), because the SE_FL_DETACHED flag is cleared once an
applet is attached.
Note this design change reverts, in intent, the commit
a33ff7a8a
("BUG/MEDIUM: conn-stream: Set back CS to RDY state when the appctx is
created"). Here, the stream connector is set to the ready state when the
applet is woken up, not when the appctx is created, so the ambiguity
discussed in this commit remains solved: there is no target installed on
a stream connector in SC_ST_INI state, and the stream connector is
switched to SC_ST_RDY state before the applet starts to work.
This patch could be backported to all supported versions. But because it is
a design change, it is probably better to not backport it lower than the
3.2, and only after a period of observation. It relies on "BUG/MEDIUM:
stconn: Do not install an applet on a busy stream connector"