fix(sidecar): serialize WDA reconnect with ReentrantLock to prevent concurrent xcodebuild races

This commit is contained in:
pj committed 2026-04-25 15:55:08 +07:00
1 parent 8c6c8c85df
commit 0681272078
1 file changed
+6
@@ -488,6 +488,7 @@ private fun pngHeight(bytes: ByteArray): Int {
class IosDriverBackend(private val udid: String) : DriverBackend {
private lateinit var driver: maestro.drivers.IOSDriver
private val reconnectLock = java.util.concurrent.locks.ReentrantLock()
init {
val httpClient = xcuitest.api.OkHttpClientInstance.get()
@@ -534,10 +535,15 @@ class IosDriverBackend(private val udid: String) : DriverBackend {
val isIoFailure = generateSequence(e as Throwable) { it.cause }
.any { it is java.io.IOException }
if (!isIoFailure) throw e
reconnectLock.lock()
try {
try { driver.open(); warmup() }
catch (reconnectErr: Exception) {
throw IllegalStateException("WDA reconnect failed: $reconnectErr", e)
}
} finally {
reconnectLock.unlock()
}
block()
}
}