Hello,

I host my Django app on Dreamhost. They provide MySQL. I am getting a weird 
MySQL-related error on regular basis: "OperationalError: (2013, 'Lost 
connection to MySQL server during query')". Typical traceback is at the end 
of this message.

Typically it happens when I do 1st-2nd access to my app after long pause 
(~hour or so). Usually it works fine after that until I stop using it for 
several hours. It may be Dreamhost's problem (e.g., network connection is 
flakey) but I cannot believe it went unnoticed for so long.

Can it be Django's problem? One possibility is Django sets some timeout 
property on MySQL connection, which is too small. Or default timeout is too 
small. Maybe some code should check that connection is alive and 
re-establish it, if it is dead.

Another possibility is I am doing something wrong. Well, the app works fine 
locally without any hiccups. It works as expected after first "lost 
connection" error(s). I don't use any raw SQL.

I am at loss. I appreciate any ideas.

Thanks,

Eugene

===========================
  File "/home/myname/djsrc/django/core/handlers/base.py", line 64, in 
get_response
    response = callback(request, **param_dict)

  File "/home/myname/djsrc/django/views/generic/date_based.py", line 49, in 
archive_index
    return HttpResponse(t.render(c))

  File "/home/myname/djsrc/django/core/template.py", line 115, in render
    return self.nodelist.render(context)

  File "/home/myname/djsrc/django/core/template.py", line 440, in render
    bits.append(node.render(context))

  File "/home/myname/djsrc/django/core/template_loader.py", line 97, in 
render
    return compiled_parent.render(context)

  File "/home/myname/djsrc/django/core/template.py", line 115, in render
    return self.nodelist.render(context)

  File "/home/myname/djsrc/django/core/template.py", line 440, in render
    bits.append(node.render(context))

  File "/home/myname/djsrc/django/core/template_loader.py", line 97, in 
render
    return compiled_parent.render(context)

  File "/home/myname/djsrc/django/core/template.py", line 115, in render
    return self.nodelist.render(context)

  File "/home/myname/djsrc/django/core/template.py", line 440, in render
    bits.append(node.render(context))

  File "/home/myname/djsrc/django/core/template_loader.py", line 54, in 
render
    result = self.nodelist.render(context)

  File "/home/myname/djsrc/django/core/template.py", line 440, in render
    bits.append(node.render(context))

  File "/home/myname/djsrc/django/core/defaulttags.py", line 107, in render
    nodelist.append(node.render(context))

  File "/home/myname/djp/home/apps/blog/templatetags/blog.py", line 99, in 
render
    context['info']  = template.Template(INFO_TEMPLATE).render(context)

  File "/home/myname/djsrc/django/core/template.py", line 115, in render
    return self.nodelist.render(context)

  File "/home/myname/djsrc/django/core/template.py", line 440, in render
    bits.append(node.render(context))

  File "/home/myname/djsrc/django/core/template.py", line 470, in render
    output = resolve_variable_with_filters(self.var_string, context)

  File "/home/myname/djsrc/django/core/template.py", line 411, in 
resolve_variable_with_filters
    obj = resolve_variable(var, context)

  File "/home/myname/djsrc/django/core/template.py", line 389, in 
resolve_variable
    current = current()

  File "/home/myname/djsrc/django/utils/functional.py", line 3, in _curried
    return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + 
morekwargs.items()))

  File "/home/myname/djsrc/django/core/meta/__init__.py", line 873, in 
method_get_many_to_one
    retrieved_obj = mod.get_object(**{'%s__exact' % 
field_with_rel.rel.field_name: val})

  File "/home/myname/djsrc/django/utils/functional.py", line 3, in _curried
    return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + 
morekwargs.items()))

  File "/home/myname/djsrc/django/core/meta/__init__.py", line 1080, in 
function_get_object
    obj_list = function_get_list(opts, klass, **kwargs)

  File "/home/myname/djsrc/django/core/meta/__init__.py", line 1120, in 
function_get_list
    return list(function_get_iterator(opts, klass, **kwargs))

  File "/home/myname/djsrc/django/core/meta/__init__.py", line 1103, in 
function_get_iterator
    cursor.execute("SELECT " + (kwargs.get('distinct') and "DISTINCT " or 
"") + ",".join(select) + sql, params)

  File "/usr/lib/python2.3/site-packages/MySQLdb/cursors.py", line 137, in 
execute
    self.errorhandler(self, exc, value)

  File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line 33, 
in defaulterrorhandler
    raise errorclass, errorvalue

OperationalError: (2013, 'Lost connection to MySQL server during query')

===========================



Reply via email to