Fix race condition in ProviderLibrary (#25509)
### Description
<!-- Describe your changes. -->
Apply bugfix from internal team.
### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->