patch: call modules' exit_process in reverse order
Maxim Dounin
mdounin at mdounin.ru
Wed Apr 27 23:55:24 UTC 2022
Hello!
On Sun, Apr 24, 2022 at 04:33:04PM +0800, shanlei at asiainfo.com wrote:
> # HG changeset patch
> # User stdanley <shanlei at asiainfo.com>
> # Date 1650788278 -28800
> # Sun Apr 24 16:17:58 2022 +0800
> # Node ID 522acbe88486d027383075c8208edd6fcc0a3aa6
> # Parent a736a7a613ea6e182ff86fbadcb98bb0f8891c0b
> patch: call modules' exit_process in reverse order to solve module
> dependency.
> We once have developed a module which depends on ngx_thread_pool module.
> but nginx hungs when began to shutdown. trace shows that ngx_thread_pool
> cant finish "exit_process" because our module is using a thread, our
> module must
> call "exit_process" before ngx_thread_pool.
> so we present this patch to solve modules' dependency issue.
Thank you for the patch.
First of all, you may want to consider this section in the
development guide:
http://nginx.org/en/docs/dev/development_guide.html#threads_pitfalls
Using threads in nginx is usually a bad idea. Thread pools, in
particular, are designed to be used to offload short operations like
read() syscalls. And these operations are expected to be finished
before nginx exit, so thread pool's exit handler waits for all
threads to complete.
If you are sure you have to use threads, and thread pools in
particular, and with some long-running tasks, you may want to
consider other ways to signal your threads to exit. In
particular, checking ngx_exiting/ngx_quit/ngx_terminate
periodically might be a way to go. Though I would recommend to
reconsider using long-running thread tasks anyway.
As for the patch, it looks wrong to me. While changing the
exit_process() callback order might solve your particular
dependency issue, similar issues might easily appear with any
order.
Hope this helps.
--
Maxim Dounin
http://mdounin.ru/
More information about the nginx-devel
mailing list