Skip to content

[Core] Use optimistic locking for service principal entry reads#20408

Merged
jiasli merged 4 commits intoAzure:devfrom
jiasli:sp-concurrency
Dec 13, 2021
Merged

[Core] Use optimistic locking for service principal entry reads#20408
jiasli merged 4 commits intoAzure:devfrom
jiasli:sp-concurrency

Conversation

@jiasli
Copy link
Member

@jiasli jiasli commented Nov 18, 2021

Partially fix #20273 (fix for MSAL token cache is done by AzureAD/microsoft-authentication-extensions-for-python#100)
Ported from AzureAD/microsoft-authentication-extensions-for-python#100

Context

Sometimes, read operation is slow. This can be simulated by inserting

import time
time.sleep(5)

statements before

return json.loads(self._persistence.load())

In such case, concurrent reads can lead to exception:

# PowerShell
0..1000 | `
    Foreach-Object -Parallel {
        python -m azure.cli account get-access-token
    }

...
  File "D:\cli\py310\lib\site-packages\portalocker\utils.py", line 158, in acquire
    raise exceptions.LockException(exception)
portalocker.exceptions.LockException: (1, 'Permission denied')

Change

This PR ports the change from AzureAD/microsoft-authentication-extensions-for-python#100 to use optimistic locking for service principal entry reads.

Concurrent reads now won't trigger any exception.

Testing Guide

# PowerShell
0..1000 | `
    Foreach-Object -Parallel {
        python -m azure.cli account get-access-token
    }

@jiasli jiasli self-assigned this Nov 18, 2021
@jiasli jiasli added the MSAL label Nov 18, 2021
@jiasli jiasli added this to the Nov 2021 (2021-12-07) milestone Nov 18, 2021
@yonzhan
Copy link
Collaborator

yonzhan commented Nov 18, 2021

Auth

@jiasli
Copy link
Member Author

jiasli commented Nov 22, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@jiasli jiasli changed the title [Auth] Use optimistic locking for service principal entry reads [Core] Use optimistic locking for service principal entry reads Dec 13, 2021
@jiasli jiasli merged commit c8f70b0 into Azure:dev Dec 13, 2021
@jiasli jiasli deleted the sp-concurrency branch December 13, 2021 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Permission denied on msal_token_cache.bin.lockfile

5 participants