Skip to content

Commit

Permalink
#425 fixed wrong locks in coroutines, causing server to hang
Browse files Browse the repository at this point in the history
  • Loading branch information
bugy committed Apr 5, 2021
1 parent e26ecc8 commit 5572cd4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/auth/auth_abstract_oauth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import abc
import asyncio
import json
import logging
import os
Expand Down Expand Up @@ -64,7 +65,7 @@ def __init__(self, oauth_authorize_url, oauth_token_url, oauth_scope, params_dic
self._validate_dump_file(self.dump_file)

self._users = {} # type: Dict[str, _UserState]
self._user_locks = defaultdict(lambda: threading.Lock())
self._user_locks = defaultdict(lambda: asyncio.locks.Lock())

self.timer = None
if self.dump_file:
Expand Down Expand Up @@ -221,7 +222,7 @@ def update_user_auth(self, username, user_state, access_token):
if not ttl_expired:
return

tornado.ioloop.IOLoop.current().add_callback(
tornado.ioloop.IOLoop.current().spawn_callback(
self._do_update_user_auth_async,
username,
user_state,
Expand All @@ -230,7 +231,7 @@ def update_user_auth(self, username, user_state, access_token):
async def _do_update_user_auth_async(self, username, user_state, access_token):
lock = self._user_locks[username]

with lock:
async with lock:
now = time.time()

ttl_expired = (user_state.last_auth_update is None) \
Expand Down

0 comments on commit 5572cd4

Please sign in to comment.