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

Fix #5597: if sync is running, don't schedule a bg task #5843

Merged
merged 1 commit into from
Dec 2, 2019
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
34 changes: 25 additions & 9 deletions Client/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIViewControllerRestorati
shutdownWebServer = singleShotTimer

if #available(iOS 13.0, *) {
scheduleBGSync()
scheduleBGSync(application: application)
} else {
syncOnDidEnterBackground(application: application)
}
Expand Down Expand Up @@ -549,14 +549,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIViewControllerRestorati
}

@available(iOS 13.0, *)
private func scheduleBGSync() {
let request = BGProcessingTaskRequest(identifier: "org.mozilla.ios.sync.part1")
request.earliestBeginDate = Date(timeIntervalSinceNow: 1)
request.requiresNetworkConnectivity = true
do {
try BGTaskScheduler.shared.submit(request)
} catch {
NSLog(error.localizedDescription)
private func scheduleBGSync(application: UIApplication) {
if profile?.syncManager.isSyncing ?? false {
// If syncing, create a bg task because _shutdown() is blocking and might take a few seconds to complete
var taskId = UIBackgroundTaskIdentifier(rawValue: 0)
taskId = application.beginBackgroundTask(expirationHandler: {
application.endBackgroundTask(taskId)
})

DispatchQueue.main.async {
self.profile?._shutdown()
application.endBackgroundTask(taskId)
}
} else {
// Blocking call, however without sync running it should be instantaneous
profile?._shutdown()

let request = BGProcessingTaskRequest(identifier: "org.mozilla.ios.sync.part1")
request.earliestBeginDate = Date(timeIntervalSinceNow: 1)
request.requiresNetworkConnectivity = true
do {
try BGTaskScheduler.shared.submit(request)
} catch {
NSLog(error.localizedDescription)
}
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions Storage/Rust/RustLogins.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,18 @@ public class RustLogins {
return error
}

public func forceClose() -> NSError? {
var error: NSError?

public func interrupt() {
do {
try storage.interrupt()
} catch let err as NSError {
error = err

Sentry.shared.sendWithStacktrace(message: "Error interrupting Logins database", tag: SentryTag.rustLogins, severity: .error, description: err.localizedDescription)
}
}

public func forceClose() -> NSError? {
var error: NSError?

interrupt()

queue.sync {
guard isOpen else { return }
Expand Down
4 changes: 4 additions & 0 deletions Storage/Rust/RustPlaces.swift
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ public class RustPlaces {
return error
}

public func interrupt() {
api?.interrupt()
}

public func forceClose() -> NSError? {
var error: NSError? = nil

Expand Down