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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

## 5.X.X (TBD)

### Bug Fixes

* Prevent potential crash in session delivery during app teardown [#308](https://github.com/bugsnag/bugsnag-cocoa/pull/308)

## 5.16.3 (14 Aug 2018)

### Bug Fixes
Expand Down
4 changes: 4 additions & 0 deletions Source/BugsnagApiClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ - (NSMutableURLRequest *)prepareRequest:(NSURL *)url
return request;
}

- (void)dealloc {
[self.sendQueue cancelAllOperations];
}

@end

@implementation BSGDelayOperation
Expand Down
11 changes: 7 additions & 4 deletions Source/BugsnagSessionTrackingApiClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ - (NSOperation *)deliveryOperation {
}

- (void)deliverSessionsInStore:(BugsnagSessionFileStore *)store {
NSString *apiKey = [self.config.apiKey copy];
NSURL *sessionURL = [self.config.sessionURL copy];

[self.sendQueue addOperationWithBlock:^{
if (!self.config.apiKey) {
if (!apiKey) {
bsg_log_err(@"No API key set. Refusing to send sessions.");
return;
}
Expand All @@ -41,16 +44,16 @@ - (void)deliverSessionsInStore:(BugsnagSessionFileStore *)store {
if (sessionCount > 0) {
NSDictionary *HTTPHeaders = @{
@"Bugsnag-Payload-Version": @"1.0",
@"Bugsnag-API-Key": self.config.apiKey,
@"Bugsnag-API-Key": apiKey,
@"Bugsnag-Sent-At": [BSG_RFC3339DateTool stringFromDate:[NSDate new]]
};
[self sendData:payload
withPayload:[payload toJson]
toURL:self.config.sessionURL
toURL:sessionURL
headers:HTTPHeaders
onCompletion:^(id data, BOOL success, NSError *error) {
if (success && error == nil) {
bsg_log_info(@"Sent %lu sessions to Bugsnag", (unsigned long)sessionCount);
bsg_log_info(@"Sent %lu sessions to Bugsnag", (unsigned long) sessionCount);

for (NSString *fileId in fileIds) {
[store deleteFileWithId:fileId];
Expand Down