                 removeSchemeTask(urlSchemeTask: urlSchemeTask)
                 return
             }
-            DispatchQueue.global(qos: .userInitiated).async {
+            // IMPORTANT: Ensure the urlSchemeTask is not strongly captured by this block operation
+            // Otherwise it will sometimes be deallocated on a non-main thread, causing a crash https://phabricator.wikimedia.org/T224113
+            let op = BlockOperation { [weak urlSchemeTask] in
                 if let cachedResponse = self.defaultHandler.cachedResponseForURL(defaultURL) {
                     DispatchQueue.main.async {
+                        guard let urlSchemeTask = urlSchemeTask else {
+                            return
+                        }
+                        self.activeCacheOperations.removeValue(forKey: urlSchemeTask.request)
                         urlSchemeTask.didReceive(cachedResponse.response)
                         urlSchemeTask.didReceive(cachedResponse.data)
                         urlSchemeTask.didFinish()

                    urlSchemeTask.didReceive(response)
                }
            }
        }, data: { data in
            DispatchQueue.main.async {
                guard self.schemeTaskIsActive(urlSchemeTask: urlSchemeTask) else {
                    return
                }
                urlSchemeTask.didReceive(data)
            }
        }, success: {
            DispatchQueue.main.async {
                guard self.schemeTaskIsActive(urlSchemeTask: urlSchemeTask) else {
                    return
                }

        
        removeSchemeTask(urlSchemeTask: urlSchemeTask)
        
        if let task = activeSessionTasks[urlSchemeTask.request] {
            removeSessionTask(request: urlSchemeTask.request)

            switch task.state {
            case .canceling:
                fallthrough
            case .completed:
                break
            default:
                task.cancel()
            }
        }
        
        if let op = activeCacheOperations.removeValue(forKey: urlSchemeTask.request) {
            op.cancel()
        }
    }
}
