Skip to content
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

Replace dispatch_semaphore use with os_unfair_lock. #324

Merged
merged 2 commits into from
Oct 7, 2022

Conversation

mwyman
Copy link
Contributor

@mwyman mwyman commented Oct 5, 2022

Xcode 14 thread checker has flagged potential priority inversion issues relating to use of dispatch_semaphore when handling session creation and dispatcher resetting. This replaces uses of semaphores with os_unfair_lock which is available on iOS 10+ and all other platforms we're concerned with.

To avoid the danger of leaking the lock, this also refactors session creation by having GTMSessionFetcher instances provide a session creation block to the service, which is only called if the service does not have an active NSURLSession.

@mwyman mwyman requested a review from thomasvl October 5, 2022 23:08
// the session has been created (or fails to be created) to avoid a hang.
session = _delegateDispatcher.session;
if (!session) {
session = creationBlock(_delegateDispatcher);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try/catch on this to avoid going to a bad state?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe just a try/finally? Or are you comfortable in it should never throw?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was thinking it should be fine, but for safety's sake yeah it should probably have try/finally to ensure the lock is released.

@thomasvl
Copy link
Member

thomasvl commented Oct 6, 2022

Do we also raise the min versions?

@thomasvl
Copy link
Member

thomasvl commented Oct 6, 2022

Do we also raise the min versions?

I thought I saw one build error about availability, but now I don't see it.

@mwyman mwyman force-pushed the replace-semaphore branch from a162c0e to 8908422 Compare October 7, 2022 18:24
thomasvl
thomasvl previously approved these changes Oct 7, 2022
mwyman added 2 commits October 7, 2022 13:48
Xcode 14 thread checker has flagged potential priority inversion issues relating to use of `dispatch_semaphore` when handling session creation and dispatcher resetting. This replaces uses of semaphores with `os_unfair_lock` which is available on iOS 10+ and all other platforms we're concerned with.

To avoid the danger of leaking the lock, this also refactors session creation by having `GTMSessionFetcher` instances provide a session creation block to the service, which is only called if the service does not have an active `NSURLSession`.
Ensures that even if `creationBlock` throws, the lock is properly unlocked.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy