launching a user thread from a module

xdrew nginx-forum at
Tue Apr 13 14:13:11 UTC 2021


I'd like to spawn a single custom thread as a part of my nginx module. The
idea is that it can be used to perform some periodic tasks, asynchronously
and independently from HTTP requests. (In other words, I use nginx/module as
a framework.) And here I faced with a problem: when I launch my thread in
different module hooks, it got killed as soon as parent process exits. So
naturally I should be doing this from the master process context, i.e. in
init_master hook - which is not implemented, according to the documentation.
Is there another place which I can use to launch a user thread?


P.S. I also tried to offload my thread function as a task to a nginx-managed
thread_pool, but this also did not work, as it seems in the stages where I
try to use thread_pool (init_module, postconfig), it is not yet fully
initialized and a call to ngx_thread_task_post crashes when accessing some
queue structure which is zero at that moment.

Posted at Nginx Forum:,291244,291244#msg-291244

More information about the nginx mailing list