Hello!
On Tue, Jun 16, 2015 at 9:49 AM, David Birdsong wrote:
> Ok, what about every init_worker_by_lua appending it's pid to a serialized
> list in shm inside a resty-lock.
>
Be prepared with abnormal cases that a worker crashes or something. It
should not usually happen but it MAY happen.
> When a timer fires w/ premature set, the worker locks, removes it's pid,
> unlocks, then locks again and checks the pid list?
>
This is fragile for extreme cases where a worker exits abnormally
(like crashing). You need to be prepared for that though it usually
won't happen.
> I'm trying to add a hook that would deregister a service in consul but cut
> down on service register/deregister churn. If a new worker arrives so late
> that the old worker can't detect it in the shm list of pids, than the
> service should be deregistered anyway IMO.
>
I think you should just add the HUP reload check in init_by_lua and a
trigger in a re-occuring timer created in init_worker_by_lua that only
fires for one of the workers (with lua-resty-lock or just a special
flag in shdict). And yeah, a timestamp is recorded in init_by_lua and
you need to compare it with the current one in init_worker_by_lua.
> As I understand timers, they're similar to a connection,
Yes.
> so can a timer hold
> up a worker's exiting or is there a cutoff time?
>
Neither. All pending timers will expire immediately and have their
handlers called with the premature argument set.
Regards,
-agentzh