#8583 closed defect (fixed)
infinite redirect loop
Reported by: | anonymous | Owned by: | Christian Boos |
---|---|---|---|
Priority: | normal | Milestone: | 0.11.6 |
Component: | web frontend | Version: | 0.11.5 |
Severity: | normal | Keywords: | |
Cc: | klaus.welch@… | Branch: | |
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
Since trac 0.11.5 redirecting to login-page for anonymous user does not work anymore.
This seems on the first glance like a setup/configuration/plugin issue (AuthRequiredPlugin or PermRedirectPlugin) but after much of trial and investigation i think it's not.
If i compare the apache error_log of an 0.11.4 installation with the same log after upgrading to 0.11.5 the difference becomes obvious.
0.11.4 system, apache error log:
[Thu Aug 20 16:50:08 2009] [error] [client 10.17.16.121] mod_python (pid=4008, interpreter='main_interpreter', phase='PythonHandler', handler='trac.web.modpython_frontend'): Application error [Thu Aug 20 16:50:08 2009] [error] [client 10.17.16.121] ServerName: 'socver02.verigy.net' [Thu Aug 20 16:50:08 2009] [error] [client 10.17.16.121] DocumentRoot: '/users/atsscm/webadmin/htdocs/' [Thu Aug 20 16:50:08 2009] [error] [client 10.17.16.121] URI: '/trac/TPdev/wiki' [Thu Aug 20 16:50:08 2009] [error] [client 10.17.16.121] Location: '/trac' [Thu Aug 20 16:50:08 2009] [error] [client 10.17.16.121] Directory: None [Thu Aug 20 16:50:08 2009] [error] [client 10.17.16.121] Filename: '/users/atsscm/webadmin/htdocs/trac' [Thu Aug 20 16:50:08 2009] [error] [client 10.17.16.121] PathInfo: '/TPdev/wiki' [Thu Aug 20 16:50:08 2009] [error] [client 10.17.16.121] Traceback (most recent call last): [Thu Aug 20 16:50:08 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/mod_python/importer.py", line 1537, in HandlerDispatch\n default=default_handler, arg=req, silent=hlist.silent) [Thu Aug 20 16:50:08 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/mod_python/importer.py", line 1229, in _process_target\n result = _execute_target(config, req, object, arg) [Thu Aug 20 16:50:08 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/mod_python/importer.py", line 1128, in _execute_target\n result = object(arg) [Thu Aug 20 16:50:08 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/web/modpython_frontend.py", line 149, in handler\n gateway.run(dispatch_request) [Thu Aug 20 16:50:08 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/web/wsgi.py", line 87, in run\n response = application(self.environ, self._start_response) [Thu Aug 20 16:50:08 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/web/main.py", line 406, in dispatch_request\n return _dispatch_request(req, env, env_error) [Thu Aug 20 16:50:08 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/web/main.py", line 463, in _dispatch_request\n req.chrome['notices'].append(Markup( [Thu Aug 20 16:50:08 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/web/api.py", line 194, in __getattr__\n value = self.callbacks[name](self) [Thu Aug 20 16:50:08 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/web/chrome.py", line 476, in prepare_request\n for category, name, text in contributor.get_navigation_items(req): [Thu Aug 20 16:50:08 2009] [error] [client 10.17.16.121] File "build/bdist.linux-i686/egg/tracauthrequired/authrequired.py", line 60, in get_navigation_items\n req.redirect(req.href.login(referer = req.abs_href(req.path_info))) [Thu Aug 20 16:50:08 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/web/api.py", line 318, in redirect\n raise RequestDone [Thu Aug 20 16:50:08 2009] [error] [client 10.17.16.121] RequestDone
0.11.5 system, apache error_log:
[Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] mod_python (pid=4553, interpreter='main_interpreter', phase='PythonHandler', handler='trac.web.modpython_frontend'): Application error [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] ServerName: 'socver02.verigy.net' [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] DocumentRoot: '/users/atsscm/webadmin/htdocs/' [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] URI: '/trac/TPdev/wiki' [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] Location: '/trac' [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] Directory: None [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] Filename: '/users/atsscm/webadmin/htdocs/trac' [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] PathInfo: '/TPdev/wiki' [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] Traceback (most recent call last): [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/mod_python/importer.py", line 1537, in HandlerDispatch\n default=default_handler, arg=req, silent=hlist.silent) [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/mod_python/importer.py", line 1229, in _process_target\n result = _execute_target(config, req, object, arg) [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/mod_python/importer.py", line 1128, in _execute_target\n result = object(arg) [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/Trac-0.11.5-py2.5.egg/trac/web/modpython_frontend.py", line 149, in handler\n gateway.run(dispatch_request) [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/Trac-0.11.5-py2.5.egg/trac/web/wsgi.py", line 92, in run\n response = application(self.environ, self._start_response) [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/Trac-0.11.5-py2.5.egg/trac/web/main.py", line 414, in dispatch_request\n return _dispatch_request(req, env, env_error) [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/Trac-0.11.5-py2.5.egg/trac/web/main.py", line 472, in _dispatch_request\n req.chrome['notices'].append(Markup( [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/Trac-0.11.5-py2.5.egg/trac/web/api.py", line 195, in __getattr__\n value = self.callbacks[name](self) [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/Trac-0.11.5-py2.5.egg/trac/web/chrome.py", line 489, in prepare_request\n for category, name, text in contributor.get_navigation_items(req): [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "build/bdist.linux-i686/egg/tracauthrequired/authrequired.py", line 60, in get_navigation_items\n req.redirect(req.href.login(referer = req.abs_href(req.path_info))) [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/Trac-0.11.5-py2.5.egg/trac/web/api.py", line 303, in redirect\n listener(self, url, permanent) [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/Trac-0.11.5-py2.5.egg/trac/web/chrome.py", line 193, in _save_messages\n for (i, message) in enumerate(req.chrome[type_]): [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/Trac-0.11.5-py2.5.egg/trac/web/api.py", line 195, in __getattr__\n value = self.callbacks[name](self) [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/Trac-0.11.5-py2.5.egg/trac/web/chrome.py", line 489, in prepare_request\n for category, name, text in contributor.get_navigation_items(req): [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "build/bdist.linux-i686/egg/tracauthrequired/authrequired.py", line 60, in get_navigation_items\n req.redirect(req.href.login(referer = req.abs_href(req.path_info))) [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/Trac-0.11.5-py2.5.egg/trac/web/api.py", line 303, in redirect\n listener(self, url, permanent) [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/Trac-0.11.5-py2.5.egg/trac/web/chrome.py", line 193, in _save_messages\n for (i, message) in enumerate(req.chrome[type_]): [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/Trac-0.11.5-py2.5.egg/trac/web/api.py", line 195, in __getattr__\n value = self.callbacks[name](self) [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/site-packages/Trac-0.11.5-py2.5.egg/trac/web/chrome.py", line 489, in prepare_request\n for category, name, text in contributor.get_navigation_items(req): ...the last 5 lines repeated OFTEN... [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/logging/__init__.py", line 971, in debug\n apply(self._log, (DEBUG, msg, args), kwargs) [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/logging/__init__.py", line 1101, in _log\n self.handle(record) [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/logging/__init__.py", line 1111, in handle\n self.callHandlers(record) [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/logging/__init__.py", line 1148, in callHandlers\n hdlr.handle(record) [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/logging/__init__.py", line 653, in handle\n self.acquire() [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] File "/users/atsscm/install/lib/python2.5/logging/__init__.py", line 604, in acquire\n self.lock.acquire() [Thu Aug 20 16:54:55 2009] [error] [client 10.17.16.121] RuntimeError: maximum recursion depth exceeded
Trac-0.11.4 terminates the redirection by throwing the 'RequestDone' exception while Trac-0.11.5 calls itself again and again.
The part which seems to me causing the error is: http://trac.edgewall.org/browser/tags/trac-0.11.5/trac/web/api.py#L302 which came in with r8271.
Attachments (0)
Change History (10)
comment:1 by , 15 years ago
comment:2 by , 15 years ago
This should work…
-
trac/web/chrome.py
189 189 def _save_messages(req, url, permanent): 190 190 """Save warnings and notices in case of redirect, so that they can 191 191 be displayed after the redirect.""" 192 for type_ in ['warnings', 'notices']: 193 for (i, message) in enumerate(req.chrome[type_]): 194 req.session['chrome.%s.%d' % (type_, i)] = message 192 if hasattr(req, 'chrome'): # don't risk a recursion (#8583) 193 for type_ in ['warnings', 'notices']: 194 for (i, message) in enumerate(req.chrome[type_]): 195 req.session['chrome.%s.%d' % (type_, i)] = message 195 196 196 197 197 198 class INavigationContributor(Interface):
comment:3 by , 15 years ago
… this also:
-
trac/web/chrome.py
445 445 446 446 chrome = {'links': {}, 'scripts': [], 'ctxtnav': [], 'warnings': [], 447 447 'notices': []} 448 req.add_redirect_listener(_save_messages)449 448 450 449 # This is ugly... we can't pass the real Request object to the 451 450 # add_xxx methods, because it doesn't yet have the chrome attribute … … 537 536 # Default theme file 538 537 chrome['theme'] = 'theme.html' 539 538 539 # if we do it earlier we risk a recursion (#8583) 540 req.add_redirect_listener(_save_messages) 541 540 542 return chrome 541 543 542 544 def get_icon_data(self, req):
Please choose your fix and test ;-)
comment:4 by , 15 years ago
I'll test it this week-end (I'm on a business trip ATM). The second patch looks nicer ;-)
comment:5 by , 15 years ago
Hi Trac-Team!
Sorry for the typo in the mentioned changeset :-| and many thanks for the fast replies!
I've tried both patches.
- The first one results in a endless loop (i had to stop apache to terminate it)
apache logs didn't show anything, trac.log was permanently increasing (loop between auth-required-plugin and trac-chrome) - The second one redirects as expected (seen in the logs) but i still get 'Internal Server Error' from apache. Maybe the exception is not caught and passed to mod_python/apache even when everything went well?
With best regards,
Klaus
PS : Trac is a really cool tool. I like the concept and extendability very much. It's of great value for our projects.
comment:6 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I believe the second fix is the correct one (applied in [8506]). With that, the PermRedirectPlugin works again. OTOH, the AuthRequiredPlugin is broken beyond repair, as it tries to redirect at a very inconvenient time (in get_navigation_items()
, which is called by Chrome.prepare_request()
, which is itself called from main._dispatch_request()
while registering the message saying that the user should log in).
comment:7 by , 15 years ago
Owner: | set to |
---|
comment:8 by , 15 years ago
The patch together with the PermRedirectPlugin works as expected.
I'll switch over to it and drop the AuthRequiredPlugin.
Many thanks for your support!
With best regards,
Klaus
follow-up: 10 comment:9 by , 15 years ago
I am running 0.11.5 with the [8506] patch applied. the permredirect stuff appears to work as expected, but I still get an infinite redirect loop on /prefs/account if a user requests a password reset and then logs in.
With r8217, you meant. Thanks for troubleshooting this.
I think we should check in
_save_messages
ifreq.chrome
is already there.