-
Notifications
You must be signed in to change notification settings - Fork 4k
[Az.Accounts] Use mutex to prevent cross process file I/O #12281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Can one of the admins verify this patch? |
@@ -87,18 +92,17 @@ public StreamWriter CreateWriter() | |||
|
|||
protected virtual void InitializeStream() | |||
{ | |||
lock (_initializationLock) | |||
_initializationLock.WaitOne(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we should use Mutex here, because TryGetStreamLock()
may open files for write exclusively, see https://github.com/Azure/azure-powershell-common/blob/master/src/Authentication.Abstractions/DiskDataStore.cs#L324
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sign off with minor comments
} | ||
_initializationLock.ReleaseMutex(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about put _initializationLock.ReleaseMutex()
in finally block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Done
} | ||
fileLock.ReleaseMutex(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest to put into finally block
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
* use mutex to prevent cross process writing to token cache file * prevent cross-process write to profile file * change log * Use "Local" mutex; put ReleaseMutex() in finally
Description
See #9448 for more info.
I also found another lock that needs to be replaced with Mutex: https://github.com/Azure/azure-powershell/blob/master/src/Accounts/Authentication.ResourceManager/ProtectedFileProvider.cs#L90
The other locks are safe.
I tested using Peter's sample code and it worked.
Checklist
CONTRIBUTING.md
ChangeLog.md
file(s) has been updated:ChangeLog.md
file can be found atsrc/{{SERVICE}}/{{SERVICE}}/ChangeLog.md
## Upcoming Release
header -- no new version header should be added