[dev] can't add timer in a module postconf init routine.

Brice Figureau brice+nginx at daysofwonder.com
Tue Oct 9 00:50:54 MSD 2007

On Mon, October 8, 2007 19:43, Manlio Perillo wrote:
> Brice Figureau ha scritto:
>> Hi,
>> I tried to ngx_add_timer the postconfiguration init callback of a
>> module,
>> but it doesn't work because ngx_event_timer_init has not yet been
>> called.
>> 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
>> there
>> 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.

> Your code in configuration callbacks will be inherited by all the worker
> processes

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).

> As an example you can use the init process callback in your ngx_module_t
> definition.

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 ?
The other problem is that I need to get my module configuration in this
callback, which I'm not sure it is possible.

Brice Figureau

More information about the nginx mailing list