diff options
author | Kali Kaneko <kali@leap.se> | 2017-02-17 16:52:07 +0100 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2017-02-17 21:03:03 +0100 |
commit | 193573cf8d44a3b6a7d8ae0e43988cffb38a428a (patch) | |
tree | 08c2b3a4c47c8e21fee25a06f0f8690d4c8ca258 | |
parent | bab34cde11bdeb2810cc9f5d223957af26b2b6d3 (diff) |
[bug] reuse wsgi threadpool
it seems evident that the functions were thought to pass a threadpool
along, but it finally wasn't properly passed and so there was a new
threadpool created to handle every resource.
I have removed the creation from the factory because I don't think it
makes sense to create a threadpool on the fly, it's prone to errors.
- Resolves: #8774
-rw-r--r-- | server/src/leap/soledad/server/_wsgi.py | 8 | ||||
-rw-r--r-- | server/src/leap/soledad/server/auth.py | 7 | ||||
-rw-r--r-- | server/src/leap/soledad/server/entrypoint.py | 10 | ||||
-rw-r--r-- | server/src/leap/soledad/server/session.py | 6 |
4 files changed, 14 insertions, 17 deletions
diff --git a/server/src/leap/soledad/server/_wsgi.py b/server/src/leap/soledad/server/_wsgi.py index a719aacb..f6ff6b26 100644 --- a/server/src/leap/soledad/server/_wsgi.py +++ b/server/src/leap/soledad/server/_wsgi.py @@ -18,7 +18,6 @@ A WSGI application that serves Soledad synchronization. """ from twisted.internet import reactor -from twisted.python import threadpool from twisted.web.wsgi import WSGIResource from leap.soledad.server import SoledadApp @@ -62,10 +61,5 @@ def init_couch_state(conf): reactor.stop() -def get_sync_resource(pool=None): - if not pool: - log.warn("NO POOL PASSED, CREATING----------") - pool = threadpool.ThreadPool() - reactor.callWhenRunning(pool.start) - reactor.addSystemEventTrigger('after', 'shutdown', pool.stop) +def get_sync_resource(pool): return WSGIResource(reactor, pool, wsgi_application) diff --git a/server/src/leap/soledad/server/auth.py b/server/src/leap/soledad/server/auth.py index e064341b..b5744fe9 100644 --- a/server/src/leap/soledad/server/auth.py +++ b/server/src/leap/soledad/server/auth.py @@ -48,8 +48,9 @@ log = Logger() @implementer(IRealm) class SoledadRealm(object): - def __init__(self, conf=None, sync_pool=None): - if not conf: + def __init__(self, sync_pool, conf=None): + assert sync_pool is not None + if conf is None: conf = get_config() blobs = conf['blobs'] self.anon_resource = SoledadAnonResource( @@ -160,7 +161,7 @@ class TokenCredentialFactory(object): raise error.LoginFailed('Invalid credentials') -def portalFactory(sync_pool=None): +def portalFactory(sync_pool): realm = SoledadRealm(sync_pool=sync_pool) checker = TokenChecker() return Portal(realm, [checker]) diff --git a/server/src/leap/soledad/server/entrypoint.py b/server/src/leap/soledad/server/entrypoint.py index 8078a54a..c06b740e 100644 --- a/server/src/leap/soledad/server/entrypoint.py +++ b/server/src/leap/soledad/server/entrypoint.py @@ -22,10 +22,12 @@ or the systemd script. """ from twisted.internet import reactor +from twisted.python import threadpool +from .auth import portalFactory +from .session import SoledadSession from ._config import get_config from ._wsgi import init_couch_state -from .session import SoledadSession # load configuration from file @@ -35,7 +37,11 @@ conf = get_config() class SoledadEntrypoint(SoledadSession): def __init__(self): - SoledadSession.__init__(self) + pool = threadpool.ThreadPool(name='wsgi') + reactor.callWhenRunning(pool.start) + reactor.addSystemEventTrigger('after', 'shutdown', pool.stop) + portal = portalFactory(pool) + SoledadSession.__init__(self, portal) # see the comments in application.py recarding why couch state has to be diff --git a/server/src/leap/soledad/server/session.py b/server/src/leap/soledad/server/session.py index c1ceb340..1c1b5345 100644 --- a/server/src/leap/soledad/server/session.py +++ b/server/src/leap/soledad/server/session.py @@ -28,7 +28,6 @@ from twisted.web.guard import HTTPAuthSessionWrapper from twisted.web.resource import ErrorPage from twisted.web.resource import IResource -from leap.soledad.server.auth import get_portal from leap.soledad.server.auth import credentialFactory from leap.soledad.server.url_mapper import URLMapper @@ -53,10 +52,7 @@ class UnauthorizedResource(wrapper.UnauthorizedResource): @implementer(IResource) class SoledadSession(HTTPAuthSessionWrapper): - def __init__(self, portal=None): - if portal is None: - portal = get_portal() - + def __init__(self, portal): self._mapper = URLMapper() self._portal = portal self._credentialFactory = credentialFactory |