Skip to content

Commit 377435a

Browse files
committed
rlm_kafka: prime librdkafka's lazy globals from .onload
Call fr_kafka_init() from mod_load (paired with fr_kafka_free() in mod_unload) so librdkafka's one-shot SSL/SASL init happens deterministically at module load time, before any worker thread gets to rd_kafka_new(). Ref-counted through libfreeradius-kafka so future kafka-family modules can share the hook.
1 parent 9940d62 commit 377435a

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/modules/rlm_kafka/rlm_kafka.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,24 @@ static int mod_instantiate(module_inst_ctx_t const *mctx)
11311131
return 0;
11321132
}
11331133

1134+
/** One-time library load hook
1135+
*
1136+
* Prime librdkafka's lazy global init (SSL lock callbacks on legacy
1137+
* OpenSSL, SASL globals if compiled in) so the first real
1138+
* `rd_kafka_new()` in a worker thread doesn't race the server's own
1139+
* OpenSSL setup. Ref-counted against any other kafka-using module.
1140+
*/
1141+
static int mod_load(void)
1142+
{
1143+
return fr_kafka_init();
1144+
}
1145+
1146+
/** Paired with mod_load */
1147+
static void mod_unload(void)
1148+
{
1149+
fr_kafka_free();
1150+
}
1151+
11341152
/** Bootstrap-phase setup
11351153
*
11361154
* Just registers the `%kafka.produce()` xlat. Topic declarations are
@@ -1163,6 +1181,8 @@ module_rlm_t rlm_kafka = {
11631181
.inst_size = sizeof(rlm_kafka_t),
11641182
.thread_inst_size = sizeof(rlm_kafka_thread_t),
11651183
.config = module_config,
1184+
.onload = mod_load,
1185+
.unload = mod_unload,
11661186
.bootstrap = mod_bootstrap,
11671187
.instantiate = mod_instantiate,
11681188
.thread_instantiate = mod_thread_instantiate,

0 commit comments

Comments
 (0)