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

Invalid task ids used for expiration handlers. #13 #14

Merged
merged 3 commits into from
Jul 30, 2015

Conversation

garrettmoon
Copy link
Collaborator

This should fix two issues:

  • Because taskID was being captured before being set, the expiration handler had an invalid taskID.
  • If the expiration handler was called, and then PINCacheEndBackgroundTask was called, it would try to end a task that had already ended.

The second case is less of an issue because I don't see it causing any problems. I've used an atomic getter / setter for taskID which should make it far less likely for there to be a race condition where endBackgroundTask is called twice with the same taskID. However it's still possible. Since this just seems to generate warnings, this seems better than the overhead of introducing a lock of some sort.

This should fix two issues:
- Because taskID was being captured before being set, the expiration handler had an invalid taskID.
- If the expiration handler was called, and then PINCacheEndBackgroundTask was called, it would try to end a task that had already ended.
@jparise
Copy link
Collaborator

jparise commented Jul 29, 2015

If we're going to introduce any intermediate object to hold the task identifier, maybe just go all the way and wrap the full background task interaction (instead of using a macro):

PINBackgroundTask *task = [[PINBackgroundTask alloc] initWithExpirationHandler:^{ ... }];
// ...
[task end];

@jaredsinclair
Copy link

lgtm. It might be nice to add a convenience class method like:

PINBackgroundTask *task = [PINBackgroundTask start];

to keep the one-liner aesthetic of the original macro.

@jparise
Copy link
Collaborator

jparise commented Jul 29, 2015

I'd prefer the PINBackgroundTask *task = [PINBackgroundTask start]; version, too.

@garrettmoon
Copy link
Collaborator Author

Sounds good, I'll update when I get access to my computer :)

garrettmoon added a commit that referenced this pull request Jul 30, 2015
Invalid task ids used for expiration handlers. #13
@garrettmoon garrettmoon merged commit d4288aa into master Jul 30, 2015
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.

3 participants