Django

Code

Ticket #8314 (closed: fixed)

Opened 4 months ago

Last modified 4 months ago

rev 8340 breaks sessions while rev 8339 works

Reported by: anonymous Assigned to: nobody
Milestone: 1.0 beta Component: django.contrib.sessions
Version: SVN Keywords:
Cc: carl@dirtcircle.com Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description (Last modified by mtredinnick)

[Thu Aug 14 11:37:26 2008] [error] [client XXX] mod_wsgi (pid=22633): Exception occurred processing WSGI script '/var/www/html/XXX/XXX-trunk/XXX.XXX.com.wsgi.py'.
[Thu Aug 14 11:37:26 2008] [error] [client XXX] Traceback (most recent call last):
[Thu Aug 14 11:37:26 2008] [error] [client XXX]   File "/var/www/html/XXX/django-trunk/django/core/handlers/wsgi.py", line 216, in __call__
[Thu Aug 14 11:37:26 2008] [error] [client XXX]     response = self.get_response(request)
[Thu Aug 14 11:37:26 2008] [error] [client XXX]   File "/var/www/html/XXX/django-trunk/django/core/handlers/base.py", line 67, in get_response
[Thu Aug 14 11:37:26 2008] [error] [client XXX]     response = middleware_method(request)
[Thu Aug 14 11:37:26 2008] [error] [client XXX]   File "/var/www/html/XXX/XXX-trunk/XXX/site/middleware.py", line 81, in process_request
[Thu Aug 14 11:37:26 2008] [error] [client XXX]     request.session['foo'] = "bar"
[Thu Aug 14 11:37:26 2008] [error] [client XXX]   File "/var/www/html/XXX/django-trunk/django/contrib/sessions/backends/base.py", line 49, in __setitem__
[Thu Aug 14 11:37:26 2008] [error] [client XXX]     self._session[key] = value
[Thu Aug 14 11:37:26 2008] [error] [client XXX]   File "/var/www/html/XXX/django-trunk/django/contrib/sessions/backends/base.py", line 161, in _get_session
[Thu Aug 14 11:37:26 2008] [error] [client XXX]     self._session_cache = self.load()
[Thu Aug 14 11:37:26 2008] [error] [client XXX]   File "/var/www/html/XXX/django-trunk/django/contrib/sessions/backends/db.py", line 19, in load
[Thu Aug 14 11:37:26 2008] [error] [client XXX]     self.create()
[Thu Aug 14 11:37:26 2008] [error] [client XXX]   File "/var/www/html/XXX/django-trunk/django/contrib/sessions/backends/db.py", line 35, in create
[Thu Aug 14 11:37:26 2008] [error] [client XXX]     self.save(must_create=True)
[Thu Aug 14 11:37:26 2008] [error] [client XXX]   File "/var/www/html/XXX/django-trunk/django/contrib/sessions/backends/db.py", line 52, in save
[Thu Aug 14 11:37:26 2008] [error] [client XXX]     session_data = self.encode(self._session),
[Thu Aug 14 11:37:26 2008] [error] [client XXX]   File "/var/www/html/XXX/django-trunk/django/contrib/sessions/backends/base.py", line 161, in _get_session
[Thu Aug 14 11:37:26 2008] [error] [client XXX]     self._session_cache = self.load()
[Thu Aug 14 11:37:26 2008] [error] [client XXX]   File "/var/www/html/XXX/django-trunk/django/contrib/sessions/backends/db.py", line 19, in load
[Thu Aug 14 11:37:26 2008] [error] [client XXX]     self.create()
[Thu Aug 14 11:37:26 2008] [error] [client XXX]   File "/var/www/html/XXX/django-trunk/django/contrib/sessions/backends/db.py", line 35, in create
[Thu Aug 14 11:37:26 2008] [error] [client XXX]     self.save(must_create=True)
[Thu Aug 14 11:37:26 2008] [error] [client XXX]   File "/var/www/html/XXX/django-trunk/django/contrib/sessions/backends/db.py", line 52, in save
[Thu Aug 14 11:37:26 2008] [error] [client XXX]     session_data = self.encode(self._session),
[Thu Aug 14 11:37:26 2008] [error] [client XXX]   File "/var/www/html/XXX/django-trunk/django/contrib/sessions/backends/base.py", line 161, in _get_session
[Thu Aug 14 11:37:26 2008] [error] [client XXX]     self._session_cache = self.load()
[Thu Aug 14 11:37:26 2008] [error] [client XXX]   File "/var/www/html/XXX/django-trunk/django/contrib/sessions/backends/db.py", line 19, in load
[Thu Aug 14 11:37:26 2008] [error] [client XXX]     self.create()
[Thu Aug 14 11:37:26 2008] [error] [client XXX]   File "/var/www/html/XXX/django-trunk/django/contrib/sessions/backends/db.py", line 35, in create
[Thu Aug 14 11:37:26 2008] [error] [client XXX]     self.save(must_create=True)
[Thu Aug 14 11:37:26 2008] [error] [client XXX]   File "/var/www/html/XXX/django-trunk/django/contrib/sessions/backends/db.py", line 52, in save
[Thu Aug 14 11:37:26 2008] [error] [client XXX]     session_data = self.encode(self._session),
[Thu Aug 14 11:37:26 2008] [error] [client XXX]   File "/var/www/html/XXX/django-trunk/django/contrib/sessions/backends/base.py", line 161, in _get_session
[Thu Aug 14 11:37:26 2008] [error] [client XXX]     self._session_cache = self.load()
[Thu Aug 14 11:37:26 2008] [error] [client XXX]   File "/var/www/html/XXX/django-trunk/django/contrib/sessions/backends/db.py", line 19, in load
[Thu Aug 14 11:37:26 2008] [error] [client XXX]     self.create()
[Thu Aug 14 11:37:26 2008] [error] [client XXX]   File "/var/www/html/XXX/django-trunk/django/contrib/sessions/backends/db.py", line 35, in create
[Thu Aug 14 11:37:26 2008] [error] [client XXX]     self.save(must_create=True)
[Thu Aug 14 11:37:26 2008] [error] [client XXX]   File "/var/www/html/XXX/django-trunk/django/contrib/sessions/backends/db.py", line 52, in save
[Thu Aug 14 11:37:26 2008] [error] [client XXX]     session_data = self.encode(self._session),
[Thu Aug 14 11:37:26 2008] [error] [client XXX]   File "/var/www/html/XXX/django-trunk/django/contrib/sessions/backends/base.py", line 161, in _get_session
.....
RuntimeError: maximum recursion depth exceeded in cmp

Attachments

session-fix.diff (1.8 kB) - added by anonymous on 08/14/08 12:41:53.

Change History

08/14/08 10:56:03 changed by mtredinnick

  • description changed.
  • needs_better_patch changed.
  • needs_tests changed.
  • version changed from 1.0-alpha to SVN.
  • milestone set to 1.0 beta.
  • needs_docs changed.

08/14/08 11:41:21 changed by Killarny

I can confirm that this is an issue. I haven't been able to recreate it again, but I definitely had a "recursion depth exceeded in cmp" problem. I reverted back to 8339 after seeing this ticket, and was able to view my site properly. Moving back up to 8340 caused the error again, which was resolved by clearing cookies in my browser. Now, I am unable to recreate the issue even by logging in under 8339 and updating to 8340, so I'm not certain what's going on. Thought I'd share though :)

08/14/08 12:10:28 changed by carljm

  • cc set to carl@dirtcircle.com.

08/14/08 12:21:51 changed by anonymous

It looks like base.py's SessionBase?._get_session calls db.py's SessionStore?.load() which calls SessionStore?.create() which calls SessionStore?.save() which tries to read _session which implicitly calls SessionBase?._get_session recursively and the whole process repeats until we run out of stack.

Should SessionStore?.save() instead skip the session_data = self.encode(_session) if we're trying to create the session since there isn't anything in it yet?

08/14/08 12:41:53 changed by anonymous

  • attachment session-fix.diff added.

08/14/08 12:42:42 changed by anonymous

I have no idea if this is the right way to fix this, but the attached patch fixes the problem for me.

08/14/08 12:47:49 changed by Alex

  • stage changed from Unreviewed to Accepted.

08/14/08 13:01:10 changed by anonymous

PS, not sure if the same recursion problem exists for the cache or file backends. I am only using the DB backend.

08/14/08 14:43:13 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(In [8351]) Fixed #8314 -- Fixed an infinite loop caused when submitting a session key (via a cookie) with no corresponding entry in the database.

This only affected the database backend, but I've applied the same fix to all three backends for robustness.

08/14/08 15:35:11 changed by anonymous

Looks like this fixed the problem for me.


Add/Change #8314 (rev 8340 breaks sessions while rev 8339 works)




Change Properties
Action