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

Prevent potential crash during app teardown #308

Merged
merged 4 commits into from
Sep 3, 2018
Merged

Conversation

fractalwrench
Copy link
Contributor

@fractalwrench fractalwrench commented Aug 16, 2018

Goal

If the session API client is garbage collected while sessions are enqueued to be delivered, there
can be a crash when accessing self.config.apiKey from the operation queue. This changeset fixes that by copying the API key/session URL accessed from within the operation block.

Changeset

Copy the sessionURL and apiKey values so that self is not accessed from the operation block.

Tests

Existing unit tests/mazerunner.

Review

For the submitter, initial self-review:

  • Commented on code changes inline explain the reasoning behind the approach
  • Reviewed the test cases added for completeness and possible points for discussion
  • A changelog entry was added for the goal of this pull request
  • Check the scope of the changeset - is everything in the diff required for the pull request?
  • This pull request is ready for:
    • Initial review of the intended approach, not yet feature complete
    • Structural review of the classes, functions, and properties modified
    • Final review

For the pull request reviewer(s), this changeset has been reviewed for:

  • Consistency across platforms for structures or concepts added or modified
  • Consistency between the changeset and the goal stated above
  • Internal consistency with the rest of the library - is there any overlap between existing interfaces and any which have been added?
  • Usage friction - is the proposed change in usage cumbersome or complicated?
  • Performance and complexity - are there any cases of unexpected O(n^3) when iterating, recursing, flat mapping, etc?
  • Concurrency concerns - if components are accessed asynchronously, what issues will arise
  • Thoroughness of added tests and any missing edge cases
  • Idiomatic use of the language

If the session API client is garbage collected while sessions are enqueued to be delivered, there
can be a crash when accessing self.config.apiKey from the operation queue.
@fractalwrench fractalwrench requested a review from a team August 16, 2018 08:40
@fractalwrench fractalwrench changed the base branch from master to next August 16, 2018 08:42
@snmaynard
Copy link
Contributor

I feel like we might want to call cancelAllOperations in dealloc of the api client instead. Do you have thoughts @kattrali?

@fractalwrench
Copy link
Contributor Author

@kattrali is Simon's suggestion something we might want to do, in addition to or in place of the fix that was originally proposed?

Copy link
Contributor

@kattrali kattrali left a comment

Choose a reason for hiding this comment

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

Agree with Simon here, in dealloc, all operations should be cancelled to avoid starting a new operation while garbage collection is occurring.

@@ -19,8 +19,11 @@ - (NSOperation *)deliveryOperation {
}

- (void)deliverSessionsInStore:(BugsnagSessionFileStore *)store {
NSString *apiKey = self.config.apiKey;
NSURL *sessionURL = self.config.sessionURL;
Copy link
Contributor

Choose a reason for hiding this comment

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

Both of these values should be copied

@fractalwrench fractalwrench merged commit 2fb5e43 into next Sep 3, 2018
@fractalwrench fractalwrench deleted the session-memory-fix branch September 3, 2018 08:09
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