`MusicDataRequest.tokenProvider` is not concurrency-safe
Originator: | darren.mo | ||
Number: | rdar://FB13373750 | Date Originated: | 2023-11-14 |
Status: | Open | Resolved: | |
Product: | MusicKit | Product Version: | iOS 17.2 Seed 1 (21C5029g) |
Classification: | Incorrect/Unexpected Behavior | Reproducible: | Always |
I have attached a sample project that tries to use `MusicDataRequest.tokenProvider` to request a token. It results in a compiler warning. Here is the relevant code: ``` private func requestDeveloperToken() async throws -> String { return try await MusicDataRequest.tokenProvider.developerToken(options: []) } ``` After setting the “Strict Concurrency Checking” Xcode build setting to “Complete”, the compiler produces the following warning: > Reference to static property 'tokenProvider' is not concurrency-safe because it involves shared mutable state Indeed, MusicKit defines `tokenProvider` as a mutable static property. Perhaps it should be made immutable?
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Apple
While you’re free to request the developer token as you are doing in this snippet of code, we also believe very few clients should have a valid reason to do so.
Indeed, all relevant MusicKit requests that need to use a developer token already take care of that automatically under the hood, including MusicCatalogResourceRequest, MusicCatalogSearchRequest, MusicPersonalRecommendationsRequest, etc. Even the general purpose data request, MusicDataRequest, does that automatically.
We would love to hear from you why you feel like you should request the developer token as you’re doing, to make sure it’s something you even need to do.
Me
Thanks for the response. I have already found that
MusicDataRequest
automatically adds the token to the URL request, so I no longer need to access thetokenProvider
property.I think there could be some changes that might make this clearer:
MusicDataRequest
documentation comment to note that it automatically adds the appropriate tokens to the URL request.tokenProvider
property or updating its documentation comment to explain its intended use case.