[dev] can't add timer in a module postconf init routine.
manlio_perillo at libero.it
Tue Oct 9 01:42:21 MSD 2007
Brice Figureau ha scritto:
> On Mon, October 8, 2007 19:43, Manlio Perillo wrote:
>> Brice Figureau ha scritto:
>>> I tried to ngx_add_timer the postconfiguration init callback of a
>>> but it doesn't work because ngx_event_timer_init has not yet been
>>> Is it possible to call ngx_event_timer_init _before_ the configuration
>>> phase ends ?
>>> My only other alternative is to lazily add my timer in the handler
>>> callback if not set yet (that works fine for sure, but I'm not sure
>>> won't be race which could create more timer than I need if there are
>>> multiple workers).
>> What do you need to do with the timer?
> I need to run cleanup code every 30s or minute per main configuration
> directive of my module.
This is interesting, I may need this for mod_wsgi.
>> Your code in configuration callbacks will be inherited by all the worker
> Yes, that's why I said I fear there is a race if the timer is added
> _after_ the configuration takes place, like in my handler (there could be
> a time frame between the moment I test the timer is not set and the moment
> I add the timer).
I don't think this is possible, since nginx does not uses preemption.
>> As an example you can use the init process callback in your ngx_module_t
> Yes I've seen. I'll try it to see if that works.
> Is the init process callback called _after_ the configuration takes place
> and after ngx_event_tiner_init ?
It is called after configuration, and I think that it is called after
the event module has been initialized.
> The other problem is that I need to get my module configuration in this
> callback, which I'm not sure it is possible.
It should be possible with ngx_get_conf:
However keep in mind that you will have a timer for each worker process,
so the cleanup code will be executed n times, unless you use shared
memory to prevent it.
Regards Manlio Perillo
More information about the nginx