introduce mutex to avoid multiple token refresh when using threads.
This commit is contained in:
@ -4,12 +4,16 @@ from mdrsclient.exceptions import UnauthorizedException
|
||||
|
||||
|
||||
def token_check(connection: MDRSConnection) -> None:
|
||||
if connection.token is not None:
|
||||
if connection.token.is_refresh_required:
|
||||
user_api = UserApi(connection)
|
||||
try:
|
||||
connection.token = user_api.refresh(connection.token)
|
||||
except UnauthorizedException:
|
||||
try:
|
||||
connection.lock.acquire()
|
||||
if connection.token is not None:
|
||||
if connection.token.is_refresh_required:
|
||||
user_api = UserApi(connection)
|
||||
try:
|
||||
connection.token = user_api.refresh(connection.token)
|
||||
except UnauthorizedException:
|
||||
connection.logout()
|
||||
elif connection.token.is_expired:
|
||||
connection.logout()
|
||||
elif connection.token.is_expired:
|
||||
connection.logout()
|
||||
finally:
|
||||
connection.lock.release()
|
||||
|
Reference in New Issue
Block a user