Another twistd server is running, PID 1915

Bug #1022129 reported by Hernan.
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ubuntu Accomplishments Daemon
Fix Released
High
Rafał Cieślak

Bug Description

elmudo@samurayPC:~$ accomplishments-viewer
Daemon seems to be installed to: /usr
/usr/lib/python2.7/dist-packages/gi/overrides/Gtk.py:391: Warning: g_object_set_property: construct property "type" for object `Window' can't be set after construction
  Gtk.Window.__init__(self, type=type, **kwds)
/usr/lib/python2.7/dist-packages/gi/overrides/Gtk.py:391: Warning: g_object_set_property: construct property "type" for object `EditExtrainfoDialog' can't be set after construction
  Gtk.Window.__init__(self, type=type, **kwds)
Starting the daemon using command `twistd -noy /usr/bin/accomplishments-daemon --logfile=/home/elmudo/.cache/accomplishments/logs/daemon.log &`
/usr/lib/python2.7/dist-packages/gi/overrides/Gtk.py:391: Warning: g_object_set_property: construct property "type" for object `AccomplishmentsViewerWindow' can't be set after construction
  Gtk.Window.__init__(self, type=type, **kwds)
Another twistd server is running, PID 1915

This could either be a previously started instance of your application or a
different application entirely. To start a new one, either run it in some other
directory, or use the --pidfile and --logfile parameters to avoid clashes.

Starting the daemon using command `twistd -noy /usr/bin/accomplishments-daemon --logfile=/home/elmudo/.cache/accomplishments/logs/daemon.log &`
Another twistd server is running, PID 1915

Tags: bitesize
Revision history for this message
Jono Bacon (jonobacon) wrote :

This is indeed a bug, but really a bug in the daemon - the daemon should really detect if another daemon is running and if it is it should not start an additional daemon. Marking it as affecting the daemon instead of the viewer.

tags: added: bitesize
Changed in ubuntu-accomplishments-viewer:
status: New → Confirmed
affects: ubuntu-accomplishments-viewer → ubuntu-accomplishments-daemon
Changed in ubuntu-accomplishments-daemon:
milestone: none → 0.3
importance: Undecided → High
Revision history for this message
Rafał Cieślak (rafalcieslak256) wrote :

That's exactly what happens. On startup twistd writes a twistd.pid file, with the process number in it. When one wants to start the daemon while another instance is running, twistd will notice the twistd.pid file, and refuse to continue.
However, since in this case the viewer tried to start the daemon, then it must mean that it failed to connect to it via DBus. It is possible that the daemon was shut down incorrectly (power outage etc.) and the pidfile is left there, preventing the daemon from starting. If so, then this could be solved by forcing twistd to write the file to a constant path (e.g. /tmp/accomplishments-daemon.pid). Then, if the daemon fails to connect to daemon, it would remove this file, just to ensure the daemon is not locked, thus it can start succesfuly.

Hernan: can you still reproduce this bug? If so, can you send contents of your ~/twistd.pid file?

Revision history for this message
Jono Bacon (jonobacon) wrote :

It seems logical for us to write the twistd.pid file to ~/.cache/accomplishments.

Revision history for this message
Rafał Cieślak (rafalcieslak256) wrote :

If the daemon is run for the first time, this directory will not exist. Therefore, if the daemon gets run then, twistd will crash as it will be unable to create the .pid file. There is not much we can do in-code to overcome this, for all that stuff happens before any piece of our code is executed.

As a side note [an idea to consider] we might want to add a new module to the daemon, say accomplishments.utils.rundaemon, which would contain 2 useful functions - one for proper starting of the daemon (taking care of correct logfile path and pidfile directory), and one for proper killing it (instead of blindly killing all twistd processes, it should read the pidfile and kill just one process with this PID).
Not only would this simplify correct start of daemon from the viewer, easily dealing with pidfile deadlocks, but would also allow us to create simple executable scripts that would take care of starting/stopping the daemon. Then, instead of
   twistd -noy /usr/share/accomplishments --logfile=/home/user/.cache/accomplishments/logs/daemon.log --pidfile=/some/other/path
and
   killall -9 twistd
we might just run
   accomplishments-daemon-launcher --start
and
   accomplishments-daemon-launcher --stop
(or any other names for these scripts). Isn't it elegant and less confusing?

Revision history for this message
Rafał Cieślak (rafalcieslak256) wrote :

Ideally, in above idea, the accomplishments-daemon script we are running through twistd would recognize if it's run directly, or via twistd - if run via twistd it should behave just as it does now, but if run directly, it should behave as the launcher for the daemon (with some wise help messages etc.). We would end up with a very elegant daemon process management!

Revision history for this message
Jono Bacon (jonobacon) wrote :

Marking as Fix Committed after Rafal's recent commit.

Changed in ubuntu-accomplishments-daemon:
status: Confirmed → Fix Committed
Changed in ubuntu-accomplishments-daemon:
assignee: nobody → Rafal Cieślak (rafalcieslak256)
Changed in ubuntu-accomplishments-daemon:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.