diff options
author | Folker Bernitt <fbernitt@thoughtworks.com> | 2016-02-24 11:06:08 +0100 |
---|---|---|
committer | Folker Bernitt <fbernitt@thoughtworks.com> | 2016-02-24 11:08:11 +0100 |
commit | 03855d3df78b4a71b880a068939e8708b0315be9 (patch) | |
tree | 50c9f071fc8aad44f24952b6fcc7b74755a8d1d7 /service/pixelated/config | |
parent | 0f9c1e66c9ab6b8f037436ffcb45d71f92d9b613 (diff) |
Recreate session on soledad problems
- Issue #615
- invalid token raised by soledad after timeout,
if we see this, recreate the session on next login
Diffstat (limited to 'service/pixelated/config')
-rw-r--r-- | service/pixelated/config/leap.py | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/service/pixelated/config/leap.py b/service/pixelated/config/leap.py index a8666086..17a69406 100644 --- a/service/pixelated/config/leap.py +++ b/service/pixelated/config/leap.py @@ -1,14 +1,13 @@ from __future__ import absolute_import -from leap.common.events import (server as events_server, - register, catalog as events) +from leap.common.events import (server as events_server) +from leap.soledad.common.errors import InvalidAuthTokenError + from pixelated.config import credentials from pixelated.bitmask_libraries.config import LeapConfig from pixelated.bitmask_libraries.certs import LeapCertificate from pixelated.bitmask_libraries.provider import LeapProvider from pixelated.bitmask_libraries.session import LeapSessionFactory from twisted.internet import defer -import os -import logging import logging log = logging.getLogger(__name__) @@ -39,11 +38,29 @@ def initialize_leap_multi_user(provider_hostname, defer.returnValue((config, provider)) +def _create_session(provider, username, password, auth): + return LeapSessionFactory(provider).create(username, password, auth) + + +def _force_close_session(session): + try: + session.close() + except Exception, e: + log.error(e) + + @defer.inlineCallbacks def authenticate_user(provider, username, password, initial_sync=True, auth=None): - leap_session = LeapSessionFactory(provider).create(username, password, auth) - if initial_sync: - yield leap_session.initial_sync() + leap_session = _create_session(provider, username, password, auth) + try: + if initial_sync: + yield leap_session.initial_sync() + except InvalidAuthTokenError: + _force_close_session(leap_session) + + leap_session = _create_session(provider, username, password, auth) + if initial_sync: + yield leap_session.initial_sync() defer.returnValue(leap_session) |