About the order of execution of the modules.

A
  • 14 Mar '21
Hello!

I am a developer of third-party modules. Assuming that all modules are registered in the same phase (e.g. NGX_HTTP_ACCESS_PHASE) I would like to know the order of execution between dynamic modules. Can I control the order of execution between dynamic modules? What is the order of execution between static and dynamic modules? Can I control the order of execution between static and dynamic modules?

I have looked at https://www.nginx.com/blog/nginx-dynamic-modules-how-they-work/#modOrder but it only gives a general overview.

ADD-SP

??? Windows 10 ???<https://go.microsoft.com/fwlink/?LinkId=550986>??

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20210314/f403d96d/attachment-0001.htm>
F
  • 14 Mar '21
On Sun, Mar 14, 2021 at 08:55:20AM +0000, ADD SP wrote:

Hi there,

> I am a developer of third-party modules. Assuming that all modules are registered in the same phase (e.g. NGX_HTTP_ACCESS_PHASE) I would like to know the order of execution between dynamic modules. Can I control the order of execution between dynamic modules? What is the order of execution between static and dynamic modules? Can I control the order of execution between static and dynamic modules?
> 

Does the "ngx_module_order" content at
http://nginx.org/en/docs/dev/development_guide.html#adding_new_modules
answer your questions?

If not: is there a specific order you wish to enforce between your modules
and stock modules; or between your modules and other non-stock modules?

Cheers,

    f
-- 
Francis Daly        francis at daoine.org
S
  • 14 Mar '21
Hi there!

Thanks for your answer!

In my module, ngx_module_type is set to HTTP, so ngx_module_order doesn't apply.

I'm sorry, I'm not sure what "stock module" means, I guess it means a built-in module, i.e. a module that can be enabled or disabled just by the parameters of the "configure" script, without having to download the source code of the module, e.g. ngx_http_flv_module and ngx_http_rewrite_module.

If I am correct, I will list below the questions I would like to ask and hopefully the questions below are clear and unambiguous.

* How to control the order of execution between the dynamic stock module and my dynamic module.
* How to control the order of execution between the dynamic stock module and my static module.
* How to control the order of execution between my dynamic non-stock modules and my dynamic modules.
* How to control the order of execution between dynamic non-stock modules and my static modules.
* How to control the order of execution between static stock modules and my dynamic modules.
* How to control the order of execution between static stock modules and my static modules.

Regarding the last question, have I looked at https://forum.nginx.org/read.php?2,246978,246999#msg-246999 and can the answers there be used to control the order between the static stock modules and my static modules?

ADD-SP
________________________________
???: nginx <nginx-bounces at nginx.org> ?? Francis Daly <francis at daoine.org>
????: 2021?3?14? 23:18
???: nginx at nginx.org <nginx at nginx.org>
??: Re: About the order of execution of the modules.

On Sun, Mar 14, 2021 at 08:55:20AM +0000, ADD SP wrote:

Hi there,

> I am a developer of third-party modules. Assuming that all modules are registered in the same phase (e.g. NGX_HTTP_ACCESS_PHASE) I would like to know the order of execution between dynamic modules. Can I control the order of execution between dynamic modules? What is the order of execution between static and dynamic modules? Can I control the order of execution between static and dynamic modules?
>

Does the "ngx_module_order" content at
http://nginx.org/en/docs/dev/development_guide.html#adding_new_modules
answer your questions?

If not: is there a specific order you wish to enforce between your modules
and stock modules; or between your modules and other non-stock modules?

Cheers,

        f
--
Francis Daly        francis at daoine.org
_______________________________________________
nginx mailing list
nginx at nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20210314/23a7a409/attachment-0001.htm>
S
  • 14 Mar '21
There are some errors in the content of my reply just now, I will re-post the question I wanted to ask, please see the previous reply for the rest of the content.

* How to control the order of execution between dynamic stock modules and my dynamic module.
* How to control the order of execution between dynamic stock modules and my static module.
* How to control the order of execution between dynamic non-stock modules and my dynamic modules.
* How to control the order of execution between dynamic non-stock modules and my static modules.
* How to control the order of execution between static stock modules and my dynamic modules.
* How to control the order of execution between static stock modules and my static modules.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20210314/acdaca20/attachment.htm>
F
  • 14 Mar '21
On Sun, Mar 14, 2021 at 05:43:19PM +0000, SP ADD wrote:

Hi there,

What follows is based on my reading of the docs; I may have missed
something, and I am happy to be corrected by someone who knows what
really happens.

> In my module, ngx_module_type is set to HTTP, so ngx_module_order doesn't apply.

It is not clear to me that that "so" statement is true.

Have you documentation to show that it is? What happened when you
tried it?

> I'm sorry, I'm not sure what "stock module" means, I guess it means a built-in module, i.e. a module that can be enabled or disabled just by the parameters of the "configure" script, without having to download the source code of the module, e.g. ngx_http_flv_module and ngx_http_rewrite_module.
> 

You are correct. Perhaps "standard" modules would have been a better
term for me to use.

> If I am correct, I will list below the questions I would like to ask and hopefully the questions below are clear and unambiguous.

What control do you want, specifically?

My reading suggests that the "static" module order is "from the
./configure line, --add-module order", and the "dynamic" module order is
"from the nginx.conf file, load_module order", where the dynamic modules
have the option to list which named modules they should run before.

(And: order is only relevant within the same phase; you did mention
that already.)

If you want more control than that, you may want to ship an nginx binary
configured the way you want it, without load_module support.

(And you probably don't want to do that.)

> * How to control the order of execution between the dynamic stock module and my dynamic module.

As the developer, I think that you do not know which stock modules are
dynamic. But you do know the names of the (current) stock modules.

If you want to be "after" a stock module, "load_module" after it in
nginx.conf.

If you want to be "before" a stock module, set your ngx_module_order to
your name then the stock module name.

> * How to control the order of execution between the dynamic stock module and my static module.

You don't.

You will be "before" (absent circumstances you can't control).

> * How to control the order of execution between my dynamic non-stock modules and my dynamic modules.

(Corrected to remove the first "my".)

load_module order, unless you-or-they know each other's names and set
ngx_module_order; in that case, whichever was last in load_module gets
to be before whichever names they nominate.

> * How to control the order of execution between dynamic non-stock modules and my static modules.

Same as dynamic stock module, except you probably do not know their
names in advance.

> * How to control the order of execution between static stock modules and my dynamic modules.

You will be "after", unless you set your ngx_module_order.

> * How to control the order of execution between static stock modules and my static modules.

./configure order.

> Regarding the last question, have I looked at https://forum.nginx.org/read.php?2,246978,246999#msg-246999 and can the answers there be used to control the order between the static stock modules and my static modules?
> 

I suspect that what is there is still fundamentally correct, yes.

Cheers,

    f
-- 
Francis Daly        francis at daoine.org
A
  • 15 Mar '21
Hi there!

Thank you very much for your help!

> It is not clear to me that that "so" statement is true.

I made a stupid mistake. I didn't recompile nginx and my modules when I debugged with GDB, so I thought that "ngx_module_order" wouldn't solve my problem, but when I retested it I found that "ngx_module_order " solved my problem. Thank you.

Here are some minor issues I would like to discuss with you.

> My reading suggests that the "static" module order is "from the
... /configure line, --add-module order", and the "dynamic" module order is
"from the nginx.conf file, load_module order", where the dynamic modules
have the option to list which named modules they should run before.

Is the order of execution of dynamic modules determined by the "load_module" order? Where did you find this? I looked at http://nginx.org/en/docs/ngx_core_module.html#load_module but did not find this statement.

> As the developer, I think that you do not know which stock modules are
But you do know the names of the (current) stock modules.

It seems that some of the stock modules (standard modules) can also be compiled as dynamic modules, e.g. " --with-stream=dynamic", so perhaps I have misunderstood something.

> You will be "after", unless you set your ngx_module_order.

I found out through GDB debugging that my module takes effect before "ngx_http_rewrite_module" if I don't set "ngx_module_order". Perhaps third party dynamic modules are executed before the stock (standard) modules?

ADD-SP
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20210315/45d413f0/attachment.htm>
F
  • 15 Mar '21
On Mon, Mar 15, 2021 at 06:49:44AM +0000, ADD SP wrote:

Hi there,

> > It is not clear to me that that "so" statement is true.
> 
> I made a stupid mistake. I didn't recompile nginx and my modules when I debugged with GDB, so I thought that "ngx_module_order" wouldn't solve my problem, but when I retested it I found that "ngx_module_order " solved my problem. Thank you.

Good that you found a thing that works :-)

As with most things software, there is "what is documented as the API
that is intended to work in the future", and there is "the current
implementation".

If you can't find a "here is the recipe to ensure that your module always
executes in *this* position in the list" document, that might be because
the product does not intend to make guarantees that that method will
remain working in the future.

So whatever is there today, should work today; and if the execution
order matters to you, then you will have to test after any update to
see whether things still work for you.

I suspect that, in the main, you are not expected to care about the full
module order. But the source is there, and nothing stops you from changing
it to work the way you want it to work. (At least: in your build.)

> Here are some minor issues I would like to discuss with you.
> 
> > My reading suggests that the "static" module order is "from the
> ... /configure line, --add-module order", and the "dynamic" module order is
> "from the nginx.conf file, load_module order", where the dynamic modules
> have the option to list which named modules they should run before.
> 
> Is the order of execution of dynamic modules determined by the "load_module" order? Where did you find this? I looked at http://nginx.org/en/docs/ngx_core_module.html#load_module but did not find this statement.

Probably the simplest thing at this stage is just to point you at the
implementation -- that is exactly what the current version of nginx does,
and any attempted explanations that contradict it are wrong.

auto/module sets the shell variable [this_module]_ORDER; auto/make reads
that and populates the C variable "char *ngx_module_order[]" for this
module; and src/core/nginx.c says what happens when a load_module directive
is read from nginx.conf, which includes reading ngx_module_order and
calling ngx_add_module() from src/core/ngx_module.c

> > As the developer, I think that you do not know which stock modules are
> But you do know the names of the (current) stock modules.
> 
> It seems that some of the stock modules (standard modules) can also be compiled as dynamic modules, e.g. " --with-stream=dynamic", so perhaps I have misunderstood something.

The person building nginx can choose (with some limitations) which
standard modules are included as static; which third-party modules are
included as static and in what order; and (sort of) whether dynamic
modules can be usefully used.

If dynamic modules can be used, then the person configuring nginx can
choose which standard-or-third-party dynamic modules are loaded, and in
which order.

> > You will be "after", unless you set your ngx_module_order.
> 
> I found out through GDB debugging that my module takes effect before "ngx_http_rewrite_module" if I don't set "ngx_module_order". Perhaps third party dynamic modules are executed before the stock (standard) modules?

Yes, I was probably unclear/misleading on that, sorry.

There is the order of loading the modules, and there is the order of
running of modules, and they are backwards with respect to each other. I
was intending to use before/after in the "loading" sense, so, unless I
got confused somewhere, please reconsider my mail in that light.

Cheers,

    f
-- 
Francis Daly        francis at daoine.org
A
  • 16 Mar '21
Hi there!

My questions have all been resolved, thank you very much!

?  If you can't find a "here is the recipe to ensure that your module always
executes in *this* position in the list" document, that might be because
the product does not intend to make guarantees that that method will
remain working in the future.

I'm emailing a question mainly because of this. Because I need to make my module compatible with other modules, but I don't want to use undefined behavior (behavior that is not defined in the standard documentation and is completely dependent on the specific implementation) to be compatible with other modules.

?  There is the order of loading the modules, and there is the order of
running of modules, and they are backwards with respect to each other. I
was intending to use before/after in the "loading" sense, so, unless I
got confused somewhere, please reconsider my mail in that light.

This is something I stumbled upon while debugging. It is indeed easy to confuse the order of initialization with the order of taking effect (execution or running), so maybe my question is a bit ambiguous.

Thanks for your help!

ADD-SP
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20210316/271389ce/attachment.htm>