Skip to content

Commit

Permalink
Guard against Data Store warmup crash (#2626)
Browse files Browse the repository at this point in the history
  • Loading branch information
bwaresiak authored Mar 26, 2024
1 parent 619e799 commit a254140
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
20 changes: 15 additions & 5 deletions Core/DataStoreWarmup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,36 @@ public class DataStoreWarmup {

private class BlockingNavigationDelegate: NSObject, WKNavigationDelegate {

let finished = PassthroughSubject<Void, Never>()
var finished: PassthroughSubject? = PassthroughSubject<Void, Never>()

func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction) async -> WKNavigationActionPolicy {
return .allow
}

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
finished.send()
if let finished {
finished.send()
self.finished = nil
} else {
Pixel.fire(pixel: .webKitWarmupUnexpectedDidFinish, includedParameters: [.appVersion])
}
}

func webViewWebContentProcessDidTerminate(_ webView: WKWebView) {
Pixel.fire(pixel: .webKitDidTerminateDuringWarmup)
// We won't get a `didFinish` if the webview crashes
finished.send()

if let finished {
finished.send()
self.finished = nil
} else {
Pixel.fire(pixel: .webKitWarmupUnexpectedDidTerminate, includedParameters: [.appVersion])
}
}

var cancellable: AnyCancellable?
func waitForLoad() async {
await withCheckedContinuation { continuation in
cancellable = finished.sink { _ in
cancellable = finished?.sink { _ in
continuation.resume()
}
}
Expand Down
10 changes: 8 additions & 2 deletions Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,10 @@ extension Pixel {
case webKitDidTerminate
case webKitTerminationDidReloadCurrentTab
case webKitDidTerminateDuringWarmup


case webKitWarmupUnexpectedDidFinish
case webKitWarmupUnexpectedDidTerminate

case backgroundTaskSubmissionFailed

case blankOverlayNotDismissed
Expand Down Expand Up @@ -999,7 +1002,10 @@ extension Pixel.Event {
case .webKitDidTerminate: return "m_d_wkt"
case .webKitDidTerminateDuringWarmup: return "m_d_webkit-terminated-during-warmup"
case .webKitTerminationDidReloadCurrentTab: return "m_d_wktct"


case .webKitWarmupUnexpectedDidFinish: return "m_d_webkit-warmup-unexpected-did-finish"
case .webKitWarmupUnexpectedDidTerminate: return "m_d_webkit-warmup-unexpected-did-terminate"

case .backgroundTaskSubmissionFailed: return "m_bt_rf"

case .blankOverlayNotDismissed: return "m_d_ovs"
Expand Down

0 comments on commit a254140

Please sign in to comment.