save-cli icon indicating copy to clipboard operation
save-cli copied to clipboard

ProcessBuilder: make `exec` suspendable

Open petertrr opened this issue 3 years ago • 5 comments

Now we have a runBlocking call inside exec, which is fine for SAVE, but makes it hard to use ProcessBuilder in save-agent inside coroutine-powered code. We should lift runBlocking higher in SAVE.

petertrr avatar Dec 09 '21 15:12 petertrr

Also, possible enhancements:

  • Log thread id in logger (because kotlin/native uses pthread)
  • logTrace when killing a process after timeout (maybe, process hangs because pkill is executed incorrectly and does nothing?)

petertrr avatar Dec 10 '21 08:12 petertrr

One more thing to consider when using save-core in multithreaded app:

kotlin.native.IncorrectDereferenceException: Trying to access top level value not marked as @ThreadLocal or @SharedImmutable from non-main thread
    at kfun:kotlin.Throwable#<init>(kotlin.String?){} (0x47ad6b)
    at kfun:kotlin.Exception#<init>(kotlin.String?){} (0x474647)
    at kfun:kotlin.RuntimeException#<init>(kotlin.String?){} (0x474837)
    at kfun:kotlin.native.IncorrectDereferenceException#<init>(kotlin.String){} (0x4a8ee7)
    at ThrowIncorrectDereferenceException (0x4c4dd6)
    at CheckGlobalsAccessible (0xa5f942)
    at kfun:org.cqfn.save.core.logging#<get-logType>(){}org.cqfn.save.core.config.LogType (0x6f9b7e)
    at kfun:org.cqfn.save.core.logging#logTrace(kotlin.String){} (0x6faa8d)
    at kfun:org.cqfn.save.core.utils.ProcessBuilder#exec(kotlin.String;kotlin.String;okio.Path?;kotlin.Long){}org.cqfn.save.core.utils.ExecutionResult (0x71079c)

petertrr avatar Dec 10 '21 11:12 petertrr

@sanyavertolet Need to add logging for each and every line in ProcessBuilder (with all the information)!

orchestr7 avatar Dec 10 '21 13:12 orchestr7

Need to consider news from coroutines project: https://github.com/JetBrains/kotlin/blob/master/kotlin-native/NEW_MM.md#update-the-libraries. Soon coroutines will move to the new memory model, we might try it now in save-cli or in save-agent.

petertrr avatar Dec 23 '21 07:12 petertrr

Some useful links: https://github.com/pgreze/kotlin-process/blob/main/src/main/kotlin/com/github/pgreze/process/Process.kt https://discuss.kotlinlang.org/t/calling-blocking-code-in-coroutines/2368/11 https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/create-coroutine.html

petertrr avatar Apr 22 '22 08:04 petertrr