##// END OF EJS Templates
db: move Session.remove to outer wsgi layer and also add it...
dan -
r669:d3c76065 stable
parent child Browse files
Show More
@@ -39,6 +39,7 b' from routes.middleware import RoutesMidd'
39 39 import routes.util
40 40
41 41 import rhodecode
42 from rhodecode.model import meta
42 43 from rhodecode.config import patches
43 44 from rhodecode.config.routing import STATIC_FILE_PREFIX
44 45 from rhodecode.config.environment import (
@@ -158,6 +159,10 b' def make_pyramid_app(global_config, **se'
158 159 pyramid_app = config.make_wsgi_app()
159 160 pyramid_app = wrap_app_in_wsgi_middlewares(pyramid_app, config)
160 161 pyramid_app.config = config
162
163 # creating the app uses a connection - return it after we are done
164 meta.Session.remove()
165
161 166 return pyramid_app
162 167
163 168
@@ -374,7 +379,25 b' def wrap_app_in_wsgi_middlewares(pyramid'
374 379 pyramid_app = make_gzip_middleware(
375 380 pyramid_app, settings, compress_level=1)
376 381
377 return pyramid_app
382
383 # this should be the outer most middleware in the wsgi stack since
384 # middleware like Routes make database calls
385 def pyramid_app_with_cleanup(environ, start_response):
386 try:
387 return pyramid_app(environ, start_response)
388 finally:
389 # Dispose current database session and rollback uncommitted
390 # transactions.
391 meta.Session.remove()
392
393 # In a single threaded mode server, on non sqlite db we should have
394 # '0 Current Checked out connections' at the end of a request,
395 # if not, then something, somewhere is leaving a connection open
396 pool = meta.Base.metadata.bind.engine.pool
397 log.debug('sa pool status: %s', pool.status())
398
399
400 return pyramid_app_with_cleanup
378 401
379 402
380 403 def sanitize_settings_and_apply_defaults(settings):
@@ -30,6 +30,7 b' import Pyro4'
30 30 import pylons
31 31 import rhodecode
32 32
33 from rhodecode.model import meta
33 34 from rhodecode.lib import hooks_base
34 35 from rhodecode.lib.utils2 import (
35 36 AttributeDict, safe_str, get_routes_generator_for_server_url)
@@ -64,7 +65,10 b' class HooksHttpHandler(BaseHTTPRequestHa'
64 65
65 66 def _call_hook(self, method, extras):
66 67 hooks = Hooks()
68 try:
67 69 result = getattr(hooks, method)(extras)
70 finally:
71 meta.Session.remove()
68 72 return result
69 73
70 74 def log_message(self, format, *args):
@@ -406,8 +406,11 b' class SimpleVCS(object):'
406 406 yield chunk
407 407 finally:
408 408 # invalidate cache on push
409 try:
409 410 if action == 'push':
410 411 self._invalidate_cache(repo_name)
412 finally:
413 meta.Session.remove()
411 414
412 415 def _get_repository_name(self, environ):
413 416 """Get repository name out of the environmnent
@@ -40,7 +40,6 b' def pylons_compatibility_tween_factory(h'
40 40 from pyramid. For example while rendering an old template that uses the
41 41 'c' or 'h' objects. This tween sets up the needed pylons globals.
42 42 """
43 try:
44 43 config = rhodecode.CONFIG
45 44 environ = request.environ
46 45 session = request.session
@@ -70,10 +69,6 b' def pylons_compatibility_tween_factory(h'
70 69 attach_context_attributes(context, request)
71 70 pylons.tmpl_context._push_object(context)
72 71 return handler(request)
73 finally:
74 # Dispose current database session and rollback uncommitted
75 # transactions.
76 meta.Session.remove()
77 72
78 73 return pylons_compatibility_tween
79 74
General Comments 0
You need to be logged in to leave comments. Login now