revert workaround in ProcessServiceImpl as pty4j 0.12.35 contains the fix for breakRead

This reverts d7863c9151274a769b0197f27aa68a3dab11b431 as pty4j was updated to 0.12.35 with 823eadafa6.

GitOrigin-RevId: 8fd4ca66cef3116642089a9bab5415533be284c0
This commit is contained in:
Sergey Simonchik
2024-08-04 14:21:07 +02:00
committed by intellij-monorepo-bot
parent ba2e1564df
commit e88dcaba3f

View File

@@ -4,25 +4,19 @@ package com.intellij.execution.process
import com.intellij.openapi.application.Application
import com.intellij.openapi.application.PathManager
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.progress.ProcessCanceledException
import com.intellij.openapi.util.SystemInfo
import com.intellij.openapi.util.registry.Registry
import com.intellij.util.ReflectionUtil
import com.pty4j.PtyProcess
import com.pty4j.PtyProcessBuilder
import com.pty4j.unix.Pty
import com.pty4j.unix.UnixPtyProcess
import com.pty4j.windows.conpty.WinConPtyProcess
import com.pty4j.windows.winpty.WinPtyProcess
import com.sun.jna.Platform
import kotlinx.coroutines.*
import org.jetbrains.annotations.ApiStatus
import org.jvnet.winp.WinProcess
import java.io.File
import java.io.OutputStream
@ApiStatus.Internal
class ProcessServiceImpl(private val coroutineScope: CoroutineScope) : ProcessService {
class ProcessServiceImpl : ProcessService {
override fun startPtyProcess(command: Array<String>,
directory: String?,
env: MutableMap<String, String>,
@@ -44,13 +38,7 @@ class ProcessServiceImpl(private val coroutineScope: CoroutineScope) : ProcessSe
.setWindowsAnsiColorEnabled(windowsAnsiColorEnabled)
.setUnixOpenTtyToPreserveOutputAfterTermination(unixOpenTtyToPreserveOutputAfterTermination)
.setSpawnProcessUsingJdkOnMacIntel(Registry.`is`("run.processes.using.pty.helper.on.mac.intel", true))
val process = builder.start()
if (process is UnixPtyProcess && Platform.isMac() && Platform.isIntel()) {
coroutineScope.launch(Dispatchers.IO + CoroutineName("Reaper for $process")) {
MacIntelPtyProcessReaper(process).run()
}
}
return process
return builder.start()
}
override fun sendWinProcessCtrlC(process: Process): Boolean {
@@ -126,47 +114,4 @@ class ProcessServiceImpl(private val coroutineScope: CoroutineScope) : ProcessSe
}
}
}
private class MacIntelPtyProcessReaper(private val process: UnixPtyProcess) {
suspend fun run() {
try {
runInterruptible {
process.waitFor()
}
}
catch (e: Exception) {
if (e is ProcessCanceledException || e is CancellationException) throw e
LOG.error("An error occurred while waiting for $process", e)
}
finally {
// We'll get here even if waiting was canceled.
// But it's still better to wake up the thread blocked on I/O than to let it block forever.
// Assuming cancellation happens for a reason, it's likely that that thread is also
// somehow canceled and wants to finish its job ASAP.
try {
process.errPty?.callBreakRead()
}
catch (e: Exception) { // These calls aren't cancellable, so no type checks here.
LOG.error("An error occurred when trying to wake up stderr of $process", e)
}
try {
process.pty?.callBreakRead()
}
catch (e: Exception) {
LOG.error("An error occurred when trying to wake up stdout of $process", e)
}
}
}
private val UnixPtyProcess.errPty: Pty?
get() = ReflectionUtil.getField(UnixPtyProcess::class.java, this, Pty::class.java, "myErrPty")
private fun Pty.callBreakRead() {
// This is an ugly temporary solution, using a deprecated API is OK here.
ReflectionUtil.getDeclaredMethod(Pty::class.java, "breakRead")!!.invoke(this)
}
}
}
private val LOG = logger<ProcessServiceImpl>()