chore: Waiting for the plugin when url test

This commit is contained in:
arm64v8a 2023-07-17 11:23:38 +09:00
parent a1ae327234
commit b525b3a964
2 changed files with 8 additions and 0 deletions

View File

@ -64,6 +64,7 @@ class GuardedProcessPool(private val onFatal: suspend (IOException) -> Unit) : C
SystemClock.elapsedRealtime() - startTime < 1000 -> throw IOException(
"$cmdName exits too fast (exit code: $exitCode)"
)
exitCode == 128 + OsConstants.SIGKILL -> Logs.w("$cmdName was killed")
else -> Logs.w(IOException("$cmdName unexpectedly exits with code $exitCode"))
}
@ -99,6 +100,7 @@ class GuardedProcessPool(private val onFatal: suspend (IOException) -> Unit) : C
}
override val coroutineContext = Dispatchers.Main.immediate + Job()
var processCount = 0
@MainThread
fun start(
@ -111,6 +113,7 @@ class GuardedProcessPool(private val onFatal: suspend (IOException) -> Unit) : C
start() // if start fails, IOException will be thrown directly
launch { looper(onRestartCallback) }
}
processCount += 1
}
@MainThread

View File

@ -8,6 +8,7 @@ import io.nekohasekai.sagernet.ktx.Logs
import io.nekohasekai.sagernet.ktx.runOnDefaultDispatcher
import io.nekohasekai.sagernet.ktx.tryResume
import io.nekohasekai.sagernet.ktx.tryResumeWithException
import kotlinx.coroutines.delay
import libcore.Libcore
import kotlin.coroutines.suspendCoroutine
@ -25,6 +26,10 @@ class TestInstance(profile: ProxyEntity, val link: String, val timeout: Int) :
try {
init()
launch()
if (processes.processCount > 0) {
// wait for plugin start
delay(500)
}
c.tryResume(Libcore.urlTest(box, link, timeout))
} catch (e: Exception) {
c.tryResumeWithException(e)