Nginx – uWSGI backtrace: semgentation fault errors

djangonginxuwsgi

I'm getting the following backtrace in my uWSGI logs, I don't know where to begin looking to figure this out:

DAMN ! worker 5 (pid: 29056) died :( trying respawn ...
Respawned uWSGI worker 5 (new pid: 29088)
DAMN ! worker 6 (pid: 29080) died :( trying respawn ...
Respawned uWSGI worker 6 (new pid: 29089)
!!! uWSGI process 29089 got Segmentation Fault !!!
*** backtrace of 29089 ***
uwsgi(uwsgi_backtrace+0x2e) [0x468a9e]
uwsgi(uwsgi_segfault+0x21) [0x468e61]
/lib/x86_64-linux-gnu/libc.so.6(+0x36d40) [0x7f74aa424d40]
/usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(_PyType_Lookup+0x19d) [0x7f74aa97572d]
...
/usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(+0x7d30d) [0x7f74aa83130d]
/usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(PyObject_Call+0x43) [0x7f74aa8dde23]
/usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(+0x12e5f5) [0x7f74aa8e25f5]
/usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(PyObject_Call+0x43) [0x7f74aa8dde23]
/usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(PyEval_CallObjectWithKeywords+0x47) [0x7f74aa89c837]
uwsgi(python_call+0x11) [0x47b011]
uwsgi(uwsgi_request_wsgi+0x116) [0x47d206]
uwsgi(wsgi_req_recv+0x8e) [0x41e64e]
uwsgi(simple_loop_run+0xc4) [0x465084]
uwsgi(uwsgi_ignition+0x194) [0x4690b4]
uwsgi(uwsgi_worker_run+0x2dd) [0x46d88d]
uwsgi(uwsgi_run+0x3b4) [0x46ddb4]
uwsgi(_start+0) [0x41dd1e]
*** end of backtrace ***

I'm running uWSGI version 2.0.9 together with django 1.7.4 and nginx 1.6 on Ubuntu 14.04 LTS.
This is my uWSGI app config:

module=project.wsgi:application
socket=127.0.0.1:7001
pidfile=/tmp/project-master.pid
master=True
vacuum=True
enable-threads=True
disable-logging=True
#limit-as=4096 # can cause problems with some application (especially on 64bit)?
max-requests=8192
processes=12
listen=12000
idle = 3600
stats=127.0.0.1:1717
memory-report = True

This is the nginx conf:

worker_processes 8; # 12 cores
worker_rlimit_nofile 100000;
pid /var/run/nginx.pid;
events {
    worker_connections 16384;
    use epoll;
    multi_accept on;
}
...

Additionally the following error appears sometimes:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 187, in __call__
    response = self.get_response(request)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 199, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 243, in handle_uncaught_exception
    return callback(request, **param_dict)
  File "./project/utils/utils.py", line 137, in error500
    return error(request, status_code, description)
  File "./project/utils/utils.py", line 127, in error
    response = render(request, 'error.html.jinja', {'description': description })
  File "/usr/local/lib/python2.7/dist-packages/django/shortcuts.py", line 50, in render
    return HttpResponse(loader.render_to_string(*args, **kwargs),
  File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py", line 178, in render_to_string
    return t.render(context_instance)
  File "/usr/local/lib/python2.7/dist-packages/django_jinja/base.py", line 139, in render
    return super(Template, self).render(new_context)
  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 982, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 746, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/var/www/pixabay/pixabay/project/templates/error.html.jinja", line 1, in top-level template code
    {% extends "base.html.jinja" %}
  File "/var/www/pixabay/pixabay/project/templates/base.html.jinja", line 37, in top-level template code
    {% spaceless %}
  File "./project/utils/templatetags/jinga2_extensions.py", line 61, in _strip_spaces
    return strip_spaces_between_tags(caller().strip())
  File "/var/www/pixabay/pixabay/project/templates/base.html.jinja", line 51, in template
    {% if request.user.is_authenticated() %}
  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 400, in getattr
    return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'django.core.handlers.wsgi.WSGIRequest object' has no attribute 'user'

This code was running without errors on a machine with 6 cores and ubuntu 12.04 LTS…
Any ideas would be great… Thanks

Best Answer

It's caused by an unbound write. This bug is fixed in 1.0, please upgrade https://pypi.python.org/pypi/xxtea/1.0

Thank for reporting the issue.