Page 1 of 1

Linux: Exiting session (reboot/shutdown) appears to cause SABnzbd to crash

Posted: June 15th, 2008, 1:46 am
by onebinary
Environment Info:
SABnzbd 0.4.0RC2
Ubuntu Linux 8.04 Hardy Heron 64bit
Default Skin

Issue: When you exit your session by either restarting or rebooting (haven't tried a Log Out yet) without using the Shutdown feature in SABnzbd, cache files are orphaned in the cache directory and never cleaned up.  In looking at the debug log, it appears that SABnzbd actually crashes (which would explain why the files are orphaned).

Impact: This ends up leaving old cruft data behind unknown to the user.

Debug Log:

Code: Select all

2008-06-14 22:56:45,500::INFO::[articlecache] Flushing <Article: article=1208236217.45999.24@news-europe.giganews.com, bytes=397388, partnum=24, art_id=SABnzbd_article_JLqH_g> to disk
2008-06-14 22:56:45,500::DEBUG::[articlecache] cache_size -> 0
2008-06-14 22:56:45,501::INFO::[sabnzbd] Saving data for SABnzbd_article_JLqH_g in /data/sabnzbd/cache/SABnzbd_article_JLqH_g
2008-06-14 22:56:48,402::DEBUG::[downloader] bps: 577820.795647
2008-06-14 22:56:48,402::ERROR::[sabnzbd] Error accessing BPSMETER?
Traceback (most recent call last):
  File "/home/onebinary/src/SABnzbd-0.4.0RC2/sabnzbd/__init__.py", line 1014, in update_bytes
    BPSMETER.update(bytes)
  File "/home/onebinary/src/SABnzbd-0.4.0RC2/sabnzbd/downloader.py", line 116, in update
    logging.debug("[%s] bps: %s", __NAME__, self.bps)
  File "/usr/lib/python2.5/logging/__init__.py", line 1327, in debug
    apply(root.debug, (msg,)+args, kwargs)
  File "/usr/lib/python2.5/logging/__init__.py", line 971, in debug
    apply(self._log, (DEBUG, msg, args), kwargs)
  File "/usr/lib/python2.5/logging/__init__.py", line 1101, in _log
    self.handle(record)
  File "/usr/lib/python2.5/logging/__init__.py", line 1111, in handle
    self.callHandlers(record)
  File "/usr/lib/python2.5/logging/__init__.py", line 1148, in callHandlers
    hdlr.handle(record)
  File "/usr/lib/python2.5/logging/__init__.py", line 655, in handle
    self.emit(record)
  File "/usr/lib/python2.5/logging/__init__.py", line 757, in emit
    self.handleError(record)
  File "/usr/lib/python2.5/logging/__init__.py", line 706, in handleError
    traceback.print_exception(ei[0], ei[1], ei[2], None, sys.stderr)
  File "/usr/lib/python2.5/traceback.py", line 124, in print_exception
    _print(file, 'Traceback (most recent call last):')
  File "/usr/lib/python2.5/traceback.py", line 13, in _print
    file.write(str+terminator)
IOError: [Errno 32] Broken pipe
2008-06-14 22:56:53,341::WARNING::[sabnzbd] Signal 15 caught, saving and exiting...
2008-06-14 22:59:40,528::INFO::--------------------------------
2008-06-14 22:59:40,551::INFO::SABnzbd.py-0.4.0RC2 (rev=1180)
It seems weird that we're seeing the Signal 15 after the crash.  I assume the Signal 15 was the kernel terminating the process during the shutdown process.  Please let me know if any additional data is needed to research this issue.

Further Discussion: Maybe it would be wise to develop some type of garbage collection for the cache directory?  Leaving cruft data, even after a crash, is never fun.

Re: Linux: Exiting session (reboot/shutdown) appears to cause SABnzbd to crash

Posted: June 15th, 2008, 3:39 am
by onebinary
I just noticed something interesting that might be related, and might even be causing the issue.  With the launch browser option, SABnzbd.py forks a firefox process, but SABnzbd holds on as the PPID.

Code: Select all

SABnzbd.py,8280 -OO /home/onebinary/src/SABnzbd-0.4.0RC2/SABnzbd.py
  ├─(firefox,8303)
  ├─{SABnzbd.py},8291
  ├─{SABnzbd.py},8292
  ├─{SABnzbd.py},8293
  ├─{SABnzbd.py},8294
...
But if firefox was already running prior to SABnzbd starting, the already running firefox sucks in the firefox instance that SABnzbd tried to launch and puts the page in a new tab.  The problem is that causes that page to be put into the already running firefox PPID and the fork that SABnzbd launched keels over:

Code: Select all

$ ps -efww | grep fire
1000      8223     1  6 01:15 ?        00:01:23 /usr/lib/firefox-3.0/firefox
1000      8303  8280  0 01:16 ?        00:00:00 [firefox] <defunct>
I think that defunct firefox PID might introduce some issues when the kernel starts shutting down processes during reboot/shutdown.

Re: Linux: Exiting session (reboot/shutdown) appears to cause SABnzbd to crash

Posted: June 15th, 2008, 4:05 am
by shypike
Obviously shutting down a system will crash SABnzbd, it never gets a proper signal to clean up its act.
So either terminate SABnzbd manually before shutting the system down or add start and stop
scripts to the system.

One example:

Code: Select all

#! /bin/sh

case "$1" in
start)
echo "Starting SABnzbd."
/usr/bin/sudo -u sabuser -H /usr/local/bin/sabnzbd -d -f /home/sabuser/.sabnzbd/sabnzbd.ini
;;
stop)
echo "Shutting down SABnzbd."
/usr/bin/wget -q --delete-after "http://HOSTADDRESS:PORT/sabnzbd/api?mode=shutdown"
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac

exit 0