[FIX] avoid systematically deadlocking the stand-alone OpenERP web in its default configuration

The default configuration for OpenERP Web standalone (launched via the
openerp-web script) is single-threaded for log-readability purposes.

web.common.controllers.main.Proxy.load has been added to wrap a
request to an HTTP handler inside a JSON (and/or JSONP) request, the
initial implementation was to perform a full HTTP call *from within an
HTTP handler to itself*.

Since the server is single-threaded and its only thread is already
busy, it can't handle the new request, and the client deadlocks.

Replaced this crap by also-crap-but-slightly-less-so: instantiating a
Werkzeug test client using the root application and proxying the
request through that. Avoids creating a new request from the server,
therefore does not deadlock.

lp bug: https://launchpad.net/bugs/905384 fixed

bzr revid: xmo@openerp.com-20111219145759-m10zgo3tcd6zjhcu
This commit is contained in:
Xavier Morel 2011-12-19 15:57:59 +01:00
parent 248654d97e
commit 75409e349a
2 changed files with 12 additions and 7 deletions

View File

@ -441,6 +441,7 @@ class Root(object):
"""
request = werkzeug.wrappers.Request(environ)
request.parameter_storage_class = werkzeug.datastructures.ImmutableDict
request.app = self
if request.path == '/':
params = urllib.urlencode(request.args)

View File

@ -248,15 +248,19 @@ class Proxy(openerpweb.Controller):
@openerpweb.jsonrequest
def load(self, req, path):
#req.config.socket_port
#if not re.match('^/[^/]+/static/.*', path):
# return werkzeug.exceptions.BadRequest()
""" Proxies an HTTP request through a JSON request.
env = req.httprequest.environ
port = env['SERVER_PORT']
It is strongly recommended to not request binary files through this,
as the result will be a binary data blob as well.
o = urllib2.urlopen('http://127.0.0.1:%s%s' % (port, path))
return o.read()
:param req: OpenERP request
:param path: actual request path
:return: file content
"""
from werkzeug.test import Client
from werkzeug.wrappers import BaseResponse
return Client(req.httprequest.app, BaseResponse).get(path).data
class Database(openerpweb.Controller):
_cp_path = "/web/database"