activation and shutdown

Lennart Poettering mzqohf at 0pointer.de
Thu Nov 5 09:46:59 PST 2009


On Thu, 05.11.09 10:45, Randell Jesup (rjesup at wgate.com) wrote:

> >On Thu, 2009-11-05 at 10:56 +0100, Kees Jongenburger wrote:
> >> Hi
> >> 
> >> I am making use of DBus activation to launch processes when needed.
> >> Overall I followed Raphaël Slinckx tutorial that can be found here
> >> http://raphael.slinckx.net/blog/documents/dbus-tutorial
> >> 
> >> Next to activation I also would like my application to shutdown when
> >> "done". How is this best done? I am mainly worried about
> >> synchronization issues for example
> >> what happens if I decide to  shutdown my service but at the same time
> >> somebody calls on me? will activation take this into account?
> >> 
> >> The most simple way I can shutdown now is to simply stop running after
> >> one method is served will that work?
> >
> >In fprintd (and a number of other daemons), we exit 30 seconds after the
> >last client has exited.
> 
> That's not sufficient to guarantee that you won't get a message right as
> you shut down - just reduces the odds.  There's an inherent timing
> window from when a device decides to shut down and when it finishes
> deregistering from the bus - if someone sends a method to you then,
> unless you're very careful you may not process the message.  I'm not
> sure how dbus handles this race condition.

You need to first unregister your name on the bus and then process all
queued messages, both incoming and outgoing, plus wait for all
asynchronous queries you might still have open to finish. Only then
you should terminate yourself.

This behaviour should fix all races, as long as clients use the
service name and not the unique connection identifier to send messages
to you. 

But if you ask me it seldomly is worth the work to fix this race. I'd
simply leave processes running forever. You could argue that a swapped
out, sleeping but loaded process is still cheaper than starting up and
shutting down services all the time.

Lennart

-- 
Lennart Poettering                        Red Hat, Inc.
lennart [at] poettering [dot] net
http://0pointer.net/lennart/           GnuPG 0x1A015CC4


More information about the dbus mailing list