Kallithea issues archive

Issue #371: kallithea 0.6.0 under python3 crashes when the --log-file option is selected

Reported by: Chris Rule
State: closed
Created on: 2020-05-08 18:38
Updated on: 2020-06-18 19:18

Description

If I start kallithea 0.6.0 stable with the --log-file option (“--log-file=/opt/kallithea/kallithea.log”), the log file is created but contains a series of gearbox errors (see below and attached). Without the --log-file option, the logs go to /var/log/syslog and appear to run correctly.

Logfile:

2020-05-08 13:31:36.785 ERROR [gearbox] Failed to load application
2020-05-08 13:31:36.785 ERROR [gearbox] 'LazyWriter' object has no attribute 'buffer'
Traceback (most recent call last):
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/gearbox/main.py", line 172, in _run_subcommand
return cmd.run(parsed_args)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/gearbox/command.py", line 31, in run
self.take_action(parsed_args)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/gearbox/commands/serve.py", line 280, in take_action
relative_to=base, global_conf=parsed_vars)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/gearbox/commands/serve.py", line 311, in loadapp
return loadapp(app_spec, name=name, relative_to=relative_to, **kw)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 253, in loadapp
return loadobj(APP, uri, name=name, **kw)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 277, in loadobj
global_conf=global_conf)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 302, in loadcontext
global_conf=global_conf)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 326, in _loadconfig
return loader.get_context(object_type, name, global_conf)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 459, in get_context
section)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 481, in _context_from_use
object_type, name=use, global_conf=global_conf)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 412, in get_context
global_conf=global_conf)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 302, in loadcontext
global_conf=global_conf)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 334, in _loadegg
return loader.get_context(object_type, name, global_conf)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 625, in get_context
object_type, name=name)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 651, in find_egg_entry_point
possible.append((entry.load(), protocol, entry.name))
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/pkg_resources/init.py", line 2450, in load
return self.resolve()
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/pkg_resources/init.py", line 2456, in resolve
module = import(self.module_name, fromlist=['name'], level=0)
File "/opt/kallithea/kallithea/kallithea/config/middleware.py", line 16, in <module>
from kallithea.config.app_cfg import base_config
File "/opt/kallithea/kallithea/kallithea/config/app_cfg.py", line 39, in <module>
from kallithea.lib.middleware.permanent_repo_url import PermanentRepoUrl
File "/opt/kallithea/kallithea/kallithea/lib/middleware/permanent_repo_url.py", line 23, in <module>
from kallithea.lib.utils import fix_repo_id_name
File "/opt/kallithea/kallithea/kallithea/lib/utils.py", line 37, in <module>
import mercurial.config
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/mercurial/config.py", line 13, in <module>
from .i18n import _
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/mercurial/i18n.py", line 15, in <module>
from .pycompat import getattr
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/mercurial/pycompat.py", line 149, in <module>
stdout = sys.stdout.buffer
AttributeError: 'LazyWriter' object has no attribute 'buffer'
2020-05-08 13:32:24.814 ERROR [gearbox] Failed to load application
2020-05-08 13:32:24.814 ERROR [gearbox] 'LazyWriter' object has no attribute 'buffer'
Traceback (most recent call last):
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/gearbox/main.py", line 172, in _run_subcommand
return cmd.run(parsed_args)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/gearbox/command.py", line 31, in run
self.take_action(parsed_args)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/gearbox/commands/serve.py", line 280, in take_action
relative_to=base, global_conf=parsed_vars)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/gearbox/commands/serve.py", line 311, in loadapp
return loadapp(app_spec, name=name, relative_to=relative_to, **kw)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 253, in loadapp
return loadobj(APP, uri, name=name, **kw)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 277, in loadobj
global_conf=global_conf)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 302, in loadcontext
global_conf=global_conf)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 326, in _loadconfig
return loader.get_context(object_type, name, global_conf)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 459, in get_context
section)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 481, in _context_from_use
object_type, name=use, global_conf=global_conf)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 412, in get_context
global_conf=global_conf)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 302, in loadcontext
global_conf=global_conf)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 334, in _loadegg
return loader.get_context(object_type, name, global_conf)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 625, in get_context
object_type, name=name)
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 651, in find_egg_entry_point
possible.append((entry.load(), protocol, entry.name))
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/pkg_resources/init.py", line 2450, in load
return self.resolve()
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/pkg_resources/init.py", line 2456, in resolve
module = import(self.module_name, fromlist=['name'], level=0)
File "/opt/kallithea/kallithea/kallithea/config/middleware.py", line 16, in <module>
from kallithea.config.app_cfg import base_config
File "/opt/kallithea/kallithea/kallithea/config/app_cfg.py", line 39, in <module>
from kallithea.lib.middleware.permanent_repo_url import PermanentRepoUrl
File "/opt/kallithea/kallithea/kallithea/lib/middleware/permanent_repo_url.py", line 23, in <module>
from kallithea.lib.utils import fix_repo_id_name
File "/opt/kallithea/kallithea/kallithea/lib/utils.py", line 37, in <module>
import mercurial.config
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/mercurial/config.py", line 13, in <module>
from .i18n import _
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/mercurial/i18n.py", line 15, in <module>
from .pycompat import getattr
File "/opt/kallithea/kallithea-venv/lib/python3.6/site-packages/mercurial/pycompat.py", line 149, in <module>
stdout = sys.stdout.buffer
AttributeError: 'LazyWriter' object has no attribute 'buffer'

Attachments

kallithea.log

Comments

Comment by Mads Kiilerich, on 2020-05-08 23:33

(Just a clarification to make sure we are aligned: gearbox is a 3rd party web/wsgi server … and the simplest one to get started. Kallithea is mainly a WSGI application that needs some web/wsgi server. It is gearbox has a `--log-file` option.)

It seems odd that “logs go to /var/log/syslog”. Gearbox with default .ini configuration will send logs to stderr where gearbox is started. If the gearbox output ends up in syslog it must be because you are launching gearbox telling it to do that. It doesn’t look like default behaviour. It seems like some kind of daemonizer is redirecting.

Anyway:

There problem here is mentioned in the TODO of https://www.mercurial-scm.org/repo/hg/rev/277f4fe6d01a#l1.7 . Gearbox with `-- log-file` will “replace std streams” and thus have a problem. The import of Mercurial will thus fail before Kallithea really gets a chance to actually run any code. The same problem will be seen if running plain hgweb with gearbox and using the --log-file option. (cc @Yuya Nishihara )

I think one good solution/workaround is to just not use the gearbox log-file option but just send stderr elsewhere.

Alternatively, I guess Kallithea will have to run workaround code at import time. That will be fragile or require full wrapping of mercurial to make sure all code paths will workaround before importing.

Comment by Chris Rule, on 2020-05-13 15:57

Your evaluation is spot on. I am using systemd to run kallithea which by default redirects stdout and stderr to /var/log/syslog.

For me what works is to, as you suggested, not use the log-file option.