patch: call modules' exit_process in reverse order

lei shan shanlei at asiainfo.com
Fri Apr 29 05:25:23 UTC 2022


helloļ¼ŒDounin,

 I also had read many discussions , confusing how to properly maintain the
dependency orders. So despite the usage of thread pool module, I think it's
a principal to call the plugin's construction , then call their destruction
functions in reverse order, when we design some kind of dynamic plugin
mechanism.

Does that make sense?


Or nginx has some consideration to force destruction follow same execution
order with construction?


Thanks & Regards

On Thu, 28 Apr 2022, 07:55 Maxim Dounin, <mdounin at mdounin.ru> wrote:

> 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/
> _______________________________________________
> nginx-devel mailing list -- nginx-devel at nginx.org
> To unsubscribe send an email to nginx-devel-leave at nginx.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20220429/f9de4697/attachment.htm>


More information about the nginx-devel mailing list