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
+9 -3
@@ -488,6 +488,7 @@ private fun pngHeight(bytes: ByteArray): Int {
class IosDriverBackend(private val udid: String) : DriverBackend { class IosDriverBackend(private val udid: String) : DriverBackend {
private lateinit var driver: maestro.drivers.IOSDriver private lateinit var driver: maestro.drivers.IOSDriver
private val reconnectLock = java.util.concurrent.locks.ReentrantLock()
init { init {
val httpClient = xcuitest.api.OkHttpClientInstance.get() val httpClient = xcuitest.api.OkHttpClientInstance.get()
@@ -534,9 +535,14 @@ class IosDriverBackend(private val udid: String) : DriverBackend {
val isIoFailure = generateSequence(e as Throwable) { it.cause } val isIoFailure = generateSequence(e as Throwable) { it.cause }
.any { it is java.io.IOException } .any { it is java.io.IOException }
if (!isIoFailure) throw e if (!isIoFailure) throw e
try { driver.open(); warmup() } reconnectLock.lock()
catch (reconnectErr: Exception) { try {
throw IllegalStateException("WDA reconnect failed: $reconnectErr", e) try { driver.open(); warmup() }
catch (reconnectErr: Exception) {
throw IllegalStateException("WDA reconnect failed: $reconnectErr", e)
}
} finally {
reconnectLock.unlock()
} }
block() block()
} }