-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

All,

Maybe I can earn myself a beer.

>> On 3/6/20 13:44, Rainer Jung wrote:
>>> no, the status unfortunately is not available as an Apache env
>>> var.
>
>>> mod_proxy_ajp has a builtin provision for automatic env var
>>> forwarding: alle env vars named AJP_SOMETHING will be
>>> forwarded as request attribute SOMETHING. But I see no easy way
>>> of detecting drain mode and setting an env var and there seems
>>> to be nothing builtin. I remember having added the forwarding
>>> for the LB activation to mod_jk many years ago but well after
>>> mod_proxy_ajp was done by Mladen. It seems to be one of the
>>> missing features in mod_proxy_ajp.
>
>> I'd of course want this to be available in mod_proxy_balancer so
>> any protocol would get it.
>
>>> But of course it could be added ...

In Apache 2.4.x, mod_proxy_balancer.c looks like this starting at line
636:

        /* Add session info to env. */
        apr_table_setn(r->subprocess_env,
                       "BALANCER_SESSION_STICKY", sticky);
        apr_table_setn(r->subprocess_env,
                       "BALANCER_SESSION_ROUTE", route);

This seems like a great place to add:

        apr_table_setn(r->subprocess_env,
                       "BALANCER_WORKER_STATUS", ???);

The question is "what should the '???' be?"

The local "proxy_worker **worker" is the place to start. It looks like
I can get the status bits using:

  (*worker)->s->status

So I could either convert that into a char* (because the environment
works on strings) or use ap_proxy_parse_wstatus to convert the status
into a human-readable char*.

In either case, what's the proper way to handle memory management for
strings in httpd/mod_proxy/etc.?

There is the brute-force yet safe:

char *status = apr_table_get(r->subprocess_env,
                            "BALANCER_WORKER_STATUS");
if(NULL == status) {
  free(status);
}

status = (char*)malloc(5 * sizeof char); // 4 characters is enough + \0

if(NULL != status) {
  if(0 <= snprintf(status, 5, "%d", (*worker)->s->status)) {
    apr_table_setn(r->subprocess_env,
                   "BALANCER_WORKER_STATUS", status);
  } else {
      apr_table_unset(r->subprocess_env,
                     "BALANCER_WORKER_STATUS");

    free(status);
  }
} else {
    apr_table_unset(r->subprocess_env,
                   "BALANCER_WORKER_STATUS");
}

This is a little wasteful, as it re-allocates a 5-byte buffer for
every request. I can get away with a /single/ allocation if I
understand the worker lifecycle a little better.

Is this moving toward the right approach?

Other thoughts:

* Would hex be a better representation?
* Would a spelled-out version be better? It looks like
ap_proxy_parse_wstatus will generate a string like "ONH".
   - How to handle memory management of the return value?
     (Is this what the apt_pool_r* is being passed-around for?)

Thanks,
- -chris
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl6QuEcACgkQHPApP6U8
pFhObg/9EXNZSta9cLCBBNnrRYpZM/+OKY9tnWjAdzOgx6X9p8uM6bOXFVTiPpor
m7+bF57bph6+bg1yxtynk13AFty9HbXkLQkPfsfoMg03SPRMWWTmHvMDV2ISIDIg
CAhKAEjMV5e5nF9gkmxVvIXKRg6ULVVF6Gjb4Dn9dlMFFjHpjqpD+AEYjS+31grf
PCt5OMmUOWyumDPOOWtP/AErmPVxIfeHT7IiK9GB+2FYpeCq1Ty98htxg6j8mbEu
qt2FMWgWGIA3WnOfidHDoTT/HEkYWoVaHQyZLJwpZI//FqUmmx4tuIRh7zRBHcdB
yiSjsO/KkbsHpQ6OkMo5Mm06++Y5l81+Cge4oPD62eUs55sh1pL45RlmlxL1ecFx
wBEOidM6ZsiJJ7x7+uuUCsXFxJXk3sFX57z0S+MLtUSBce8siBm7/+mnr3XXzhjJ
AK+C3BsNQ+yVpRB2l3cLghgr7SSDYTmnEGLfHTwqSjrP2cTxMNdHObl35enj9mr5
rDV9bgCZkwjvKgytk6u0MkZ16JUqd4v5MElGM2NQDMa0eiwWHRAcNznDQG17C8L0
9uDPO0ZjGTtB5h4OpNNx7DC5ts5X+ecMn7fIBHIJewfxXQUdAA5fdSRkrozJCq5o
WD6Tjuar78oeIiD5CRFLg6AB4m7HElcdzuPcSBRcEHpFE7Ev3t4=
=UElj
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to