Django + FastCGI - 随机提高OperationalError [英] Django + FastCGI - randomly raising OperationalError

查看:165
本文介绍了Django + FastCGI - 随机提高OperationalError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个Django应用程序。在Apache + mod_python之前,这是一切都可以了。切换到Lighttpd + FastCGI。现在我随机得到以下异常(这个地方和时间似乎似乎都不可预知)。由于它是随机的,只有在切换到FastCGI之后,我才认为它与某些设置有关。



在googleing时发现了一些结果,但是似乎与设置maxrequests = 1相关。但是,我使用默认值,这是0。



任何想法在哪里寻找?



PS。我使用PostgreSQL。也可能与此相关,因为在进行数据库查询时出现异常。

 文件/ usr / lib / python2 .6 / site-packages / django / core / handlers / base.py,第86行,get_response 
response = callback(request,* callback_args,** callback_kwargs)

文件 /usr/lib/python2.6/site-packages/django/contrib/admin/sites.py,第140行,根
如果不是self.has_permission(请求):

文件/usr/lib/python2.6/site-packages/django/contrib/admin/sites.py,第99行,has_permission
返回request.user.is_authenticated()和request.user.is_staff

文件/usr/lib/python2.6/site-packages/django/contrib/auth/middleware.py,第5行,__get__
request._cached_user = get_user(request)

文件/usr/lib/python2.6/site-packages/django/contrib/auth/__init__.py,第83行,get_user
user_id = request.session [SESSION_KEY ]

文件/usr/lib/python2.6/site-packages/django/contrib/sessions/b ackends / base.py,第46行,__getitem__
return self._session [key]

文件/usr/lib/python2.6/site-packages/django/contrib/ session / backends / base.py,第172行,_get_session
self._session_cache = self.load()

文件/usr/lib/python2.6/site-packages/ django / contrib / sessions / backends / db.py,第16行,加载
expire_date__gt = datetime.datetime.now()

文件/usr/lib/python2.6/ get-b $ b返回self.get_query_set()。get(* args,** kwargs)

文件 /usr/lib/python2.6/site-packages/django/db/models/query.py,第304行,get
num = len(clone)

文件/ usr / lib / python2.6 / site-packages / django / db / models / query.py,第160行,__len__
self._result_cache = list(self.iterator())

文件/usr/lib/python2.6/site-packages/django/db/models/query.py,第275行,迭代器
for self.query.results_iter()中的行

文件/ usr / lib / pytho n2.6 / site-packages / django / db / models / sql / query.py,第206行,在result_iter
for self.execute_sql(MULTI)中的行:

文件 /usr/lib/python2.6/site-packages/django/db/models/sql/query.py,第1734行,在execute_sql
cursor.execute(sql,params)

OperationalError:服务器意外关闭连接
这可能意味着服务器在处理请求之前或之前异常终止


解决方案

最后我切换回Apache + mod_python我有fcgi的其他随机错误,除了这一个),一切都很好,稳定现在。



问题仍然是开放的。如果有人在将来遇到这个问题并解决问题,他们可以在这里记录解决方案以备将来参考。 :)


I'm running a Django application. Had it under Apache + mod_python before, and it was all OK. Switched to Lighttpd + FastCGI. Now I randomly get the following exception (neither the place nor the time where it appears seem to be predictable). Since it's random, and it appears only after switching to FastCGI, I assume it has something to do with some settings.

Found a few results when googleing, but they seem to be related to setting maxrequests=1. However, I use the default, which is 0.

Any ideas where to look for?

PS. I'm using PostgreSQL. Might be related to that as well, since the exception appears when making a database query.

 File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 86, in get_response
   response = callback(request, *callback_args, **callback_kwargs)

 File "/usr/lib/python2.6/site-packages/django/contrib/admin/sites.py", line 140, in root
   if not self.has_permission(request):

 File "/usr/lib/python2.6/site-packages/django/contrib/admin/sites.py", line 99, in has_permission
   return request.user.is_authenticated() and request.user.is_staff

 File "/usr/lib/python2.6/site-packages/django/contrib/auth/middleware.py", line 5, in __get__
   request._cached_user = get_user(request)

 File "/usr/lib/python2.6/site-packages/django/contrib/auth/__init__.py", line 83, in get_user
   user_id = request.session[SESSION_KEY]

 File "/usr/lib/python2.6/site-packages/django/contrib/sessions/backends/base.py", line 46, in __getitem__
   return self._session[key]

 File "/usr/lib/python2.6/site-packages/django/contrib/sessions/backends/base.py", line 172, in _get_session
   self._session_cache = self.load()

 File "/usr/lib/python2.6/site-packages/django/contrib/sessions/backends/db.py", line 16, in load
   expire_date__gt=datetime.datetime.now()

 File "/usr/lib/python2.6/site-packages/django/db/models/manager.py", line 93, in get
   return self.get_query_set().get(*args, **kwargs)

 File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 304, in get
   num = len(clone)

 File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 160, in __len__
   self._result_cache = list(self.iterator())

 File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 275, in iterator
   for row in self.query.results_iter():

 File "/usr/lib/python2.6/site-packages/django/db/models/sql/query.py", line 206, in results_iter
   for rows in self.execute_sql(MULTI):

 File "/usr/lib/python2.6/site-packages/django/db/models/sql/query.py", line 1734, in execute_sql
   cursor.execute(sql, params)

OperationalError: server closed the connection unexpectedly
       This probably means the server terminated abnormally
       before or while processing the request.

解决方案

In the end I switched back to Apache + mod_python (I was having other random errors with fcgi, besides this one) and everything is good and stable now.

The question still remains open. In case anybody has this problem in the future and solves it they can record the solution here for future reference. :)

这篇关于Django + FastCGI - 随机提高OperationalError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆