OpenPanel.initialize blocks main thread / crashes on background thread due to WKWebView + DispatchSemaphore deadlock in getiOSUserAgent
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
Línea de trabajo
Start with DeviceInfo.getiOSUserAgent and trace how OpenPanel.initialize obtains and uses the user agent. Verify the behavior when initialization is called on both the main and a background thread, then make completion or fallback handling non-blocking while preserving the expected user-agent value.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
OpenPanel.initialize is not safe to call from either the main thread or a background thread due to a deadlock in the internal getiOSUserAgent implementation. This makes it impossible to initialize the SDK without causing either a crash or a ~1 second UI freeze.
Root cause
Inside DeviceInfo.getiOSUserAgent():
let webView = WKWebView(frame: .zero) // (1) must be on main thread
var userAgent = ""
let semaphore = DispatchSemaphore(value: 0)
DispatchQueue.main.async { // (2) queued on main thread
webView.evaluateJavaScript("navigator.userAgent") { (result, error) in
if let agent = result as? String { userAgent = agent }
semaphore.signal()
}
}
_ = semaphore.wait(timeout: .now() + 1.0) // (3) blocks calling thread
This creates two mutually exclusive failure scenarios:
Scenario A — Called from main thread:
Step (1) is fine.
Step (3) blocks the main thread via semaphore.wait.
Step (2)'s main.async block is queued but can never execute because the main thread is blocked.
The semaphore always times out after 1 full second, freezing the UI every time.
Scenario B — Called from a background thread:
Step (1) crashes immediately with Main Thread Checker: UI API called on a background thread: -[WKWebView .cxx_construct].
Observed crash (background thread):
Main Thread Checker: UI API called on a background thread: -[WKWebView .cxx_construct]
Queue name: com.apple.root.utility-qos
#5 OpenPanel.DeviceInfo.getiOSUserAgent()
#6 OpenPanel.DeviceInfo.getUserAgent()
#7 OpenPanel.OpenPanel.initialize(options:)
Observed freeze (main thread): OpenPanel.initialize always blocks the calling thread for exactly 1 second (the semaphore timeout), regardless of device speed, because the JS evaluation can never signal the semaphore while the thread is waiting on it.
Expected behavior
OpenPanel.initialize should be safe to call from the main thread without blocking it. The user agent should be fetched asynchronously and either:
Cached lazily on first use after a non-blocking async fetch, or
Fetched during initialize without blocking (e.g. completion-based), or
Simply use getBasicUserAgent() as the default and upgrade to the WKWebView-based UA once it becomes available asynchronously.
Suggested fix:
private static func getiOSUserAgent(completion: @escaping (String) -> Void) {
DispatchQueue.main.async {
let webView = WKWebView(frame: .zero)
webView.evaluateJavaScript("navigator.userAgent") { result, _ in
let agent = (result as? String) ?? getBasicUserAgent()
completion(agent + " OpenPanel/\(OpenPanel.sdkVersion)")
}
}
}
- Lenguaje dominante
- Swift
- Estrellas
- 5
- Forks
- 8
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Openpanel-dev/swift-sdk
-
Security around client secret?Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
Todos los issues de Openpanel-dev/swift-sdk
Issues similares
-
Bug 🐞
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
mozilla-mobile/firefox-ios#35986 ·
Los mantenedores suelen responder en 1 día
-
Reading an empty file leaks a 4 KB buffer on Linux (Data(contentsOf:), String(contentsOfFile:))Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
swiftlang/swift-foundation#2304 ·
Los mantenedores suelen responder en 1 día
-
area:caching bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
axeslasher/Jelly-Shark#321 ·
Los mantenedores suelen responder en 1 día
-
[iOS] Script init caches the wrong view model when dataBind is applied after state-machine creationPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 63/100
rive-app/rive-nitro-react-native#414 ·
Los mantenedores suelen responder en 1 día
-
type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
googleapis/google-cloud-swift#1412 · 1 comentario ·
Los mantenedores suelen responder en 1 día