Browse Source

Fix handle leak.

Caused by bug in CherryPy's memory-based session support.
Replace by file-based.
As we don't really need session support, disable it and make it available through the --sessions option.
tags/0.6.6
ShyPike 14 years ago
parent
commit
a01cd34b58
  1. 18
      SABnzbd.py
  2. 11
      sabnzbd/misc.py

18
SABnzbd.py

@ -769,7 +769,7 @@ def commandline_handler(frozen=True):
'weblogging=', 'server=', 'templates', 'weblogging=', 'server=', 'templates',
'template2', 'browser=', 'config-file=', 'force', 'template2', 'browser=', 'config-file=', 'force',
'version', 'https=', 'autorestarted', 'repair', 'repair-all', 'version', 'https=', 'autorestarted', 'repair', 'repair-all',
'log-all', 'no-login', 'pid=', 'new', 'log-all', 'no-login', 'pid=', 'new', 'sessions',
# Below Win32 Service options # Below Win32 Service options
'password=', 'username=', 'startup=', 'perfmonini=', 'perfmondll=', 'password=', 'username=', 'startup=', 'perfmonini=', 'perfmondll=',
'interactive', 'wait=', 'interactive', 'wait=',
@ -842,6 +842,7 @@ def main():
re_argv = [sys.argv[0]] re_argv = [sys.argv[0]]
pid_path = None pid_path = None
new_instance = False new_instance = False
force_sessions = False
service, sab_opts, serv_opts, upload_nzbs = commandline_handler() service, sab_opts, serv_opts, upload_nzbs = commandline_handler()
@ -922,6 +923,8 @@ def main():
re_argv.append(arg) re_argv.append(arg)
elif opt in ('--new',): elif opt in ('--new',):
new_instance = True new_instance = True
elif opt in ('--sessions',):
force_sessions = True
sabnzbd.MY_FULLNAME = os.path.normpath(os.path.abspath(sabnzbd.MY_FULLNAME)) sabnzbd.MY_FULLNAME = os.path.normpath(os.path.abspath(sabnzbd.MY_FULLNAME))
sabnzbd.MY_NAME = os.path.basename(sabnzbd.MY_FULLNAME) sabnzbd.MY_NAME = os.path.basename(sabnzbd.MY_FULLNAME)
@ -1294,6 +1297,14 @@ def main():
sabnzbd.cfg.username.set('') sabnzbd.cfg.username.set('')
sabnzbd.cfg.password.set('') sabnzbd.cfg.password.set('')
# Fix leakage in memory-based CherryPy session support by using file-based.
# However, we don't really need session support.
if force_sessions:
sessions = sabnzbd.misc.create_real_path('sessions', sabnzbd.cfg.admin_dir.get_path(), 'sessions')[1]
sabnzbd.misc.remove_all(sessions, 'session-*.lock', keep_folder=True)
else:
sessions = None
cherrypy.config.update({'server.environment': 'production', cherrypy.config.update({'server.environment': 'production',
'server.socket_host': cherryhost, 'server.socket_host': cherryhost,
'server.socket_port': cherryport, 'server.socket_port': cherryport,
@ -1303,7 +1314,10 @@ def main():
'engine.reexec_retry' : 100, 'engine.reexec_retry' : 100,
'tools.encode.on' : True, 'tools.encode.on' : True,
'tools.gzip.on' : True, 'tools.gzip.on' : True,
'tools.sessions.on' : True, 'tools.sessions.on' : bool(sessions),
'tools.sessions.storage_type' : 'file',
'tools.sessions.storage_path' : sessions,
'tools.sessions.timeout' : 60,
'request.show_tracebacks': True, 'request.show_tracebacks': True,
'checker.check_localhost' : bool(consoleLogging), 'checker.check_localhost' : bool(consoleLogging),
'error_page.401': sabnzbd.panic.error_page_401 'error_page.401': sabnzbd.panic.error_page_401

11
sabnzbd/misc.py

@ -1138,16 +1138,17 @@ def remove_dir(path):
os.rmdir(path) os.rmdir(path)
def remove_all(path, pattern='*'): def remove_all(path, pattern='*', keep_folder=False):
""" Remove folder and all its content """ Remove folder and all its content
""" """
if os.path.exists(path): if os.path.exists(path):
for f in globber(path, pattern): for f in globber(path, pattern):
os.remove(f) os.remove(f)
try: if not keep_folder:
os.rmdir(path) try:
except: os.rmdir(path)
pass except:
pass
def clean_folder(path, pattern='*'): def clean_folder(path, pattern='*'):

Loading…
Cancel
Save