     }
 
     deinit {
+        deviceTokenRetryTask = nil
         if let token = activeApplicationObservationToken {
             NotificationCenter.default.removeObserver(token)
         }

extension PushNotificationsSettingsViewController {

    fileprivate func requestPushPermissions() {
        notificationsController.requestPermissionsIfNecessary(completionHandler: { (authorized, error) in
            DispatchQueue.main.async {
                if authorized {
                    UIApplication.shared.registerForRemoteNotifications()
                    if self.notificationsController.remoteRegistrationDeviceToken == nil {
                        // If we're still awaiting a device token, offer the user the opportunity to retry fetching one
                        let retryAction = UIAlertAction(title: self.echoAlertFailureTryAgainActionTitle, style: .default, handler: { _ in self.requestPushPermissions() })
                        let cancelAction = UIAlertAction(title: CommonStrings.cancelActionTitle, style: .cancel, handler: { _ in self.updateSections() })
                        self.wmf_showAlert(title: self.echoAlertFailureTitle, message: self.echoAlertFailureMessage, actions: [retryAction, cancelAction], completion: {
                            // Silently trigger a remote registration request to fetch a device token
                            UIApplication.shared.registerForRemoteNotifications()
                        })
                    } else {
                        // User is authorized for on device push alerts and is now awaiting subscription to Echo Notifications
                        self.subscribeToEchoNotifications()

    private var activeApplicationObservationToken: NSObjectProtocol?
    private var sections: [PushNotificationsSettingsSection] = []

    fileprivate var deviceTokenRetryTask: RetryBlockTask?

    fileprivate let headerText = WMFLocalizedString("settings-notifications-header", value: "Be alerted to activity related to your account, such as messages from fellow contributors, alerts, and notices. All provided with respect to privacy and up to the minute data.", comment: "Text informing user of benefits of enabling push notifications.") + "\n"

    fileprivate let echoAlertFailureTitle = WMFLocalizedString("settings-notifications-echo-failure-title", value: "Unable to Check for Echo Notification subscriptions", comment: "Alert title text informing user of failure when subscribing to Echo Notifications.")
