From 85c6a68cafc9da591d6ab86fedd4230abf2425a9 Mon Sep 17 00:00:00 2001 From: Bela VanderVoort Date: Fri, 15 Sep 2023 22:17:50 -0500 Subject: [PATCH] Fix for the rider plugin hanging. When the error stream filled up without being read it couldn't read from the input stream was waiting indefinitely (#958) --- Src/CSharpier.Rider/CHANGELOG.md | 3 ++ Src/CSharpier.Rider/gradle.properties | 2 +- .../CSharpierProcessPipeMultipleFiles.java | 34 ++++++++++++++----- .../ReformatWithCSharpierOnSave.java | 6 ---- .../src/main/resources/META-INF/plugin.xml | 5 ++- 5 files changed, 33 insertions(+), 17 deletions(-) diff --git a/Src/CSharpier.Rider/CHANGELOG.md b/Src/CSharpier.Rider/CHANGELOG.md index 6bd207040..d5c9085f7 100644 --- a/Src/CSharpier.Rider/CHANGELOG.md +++ b/Src/CSharpier.Rider/CHANGELOG.md @@ -2,6 +2,9 @@ # csharpier-rider Changelog +## [1.3.10] +- Read from error stream to prevent the plugin hanging when the csharpier process writes too much to the error stream. + ## [1.3.9] - Wait at most 3 seconds for csharpier to format otherwise consider it hung and restart it. diff --git a/Src/CSharpier.Rider/gradle.properties b/Src/CSharpier.Rider/gradle.properties index f039a371f..eb8befb0d 100644 --- a/Src/CSharpier.Rider/gradle.properties +++ b/Src/CSharpier.Rider/gradle.properties @@ -4,7 +4,7 @@ pluginGroup = com.intellij.csharpier pluginName = csharpier # SemVer format -> https://semver.org -pluginVersion = 1.3.9 +pluginVersion = 1.3.10 # See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html # for insight into build numbers and IntelliJ Platform versions. diff --git a/Src/CSharpier.Rider/src/main/java/com/intellij/csharpier/CSharpierProcessPipeMultipleFiles.java b/Src/CSharpier.Rider/src/main/java/com/intellij/csharpier/CSharpierProcessPipeMultipleFiles.java index d8c8ce2e0..1dc52f3f9 100644 --- a/Src/CSharpier.Rider/src/main/java/com/intellij/csharpier/CSharpierProcessPipeMultipleFiles.java +++ b/Src/CSharpier.Rider/src/main/java/com/intellij/csharpier/CSharpierProcessPipeMultipleFiles.java @@ -3,16 +3,8 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.diagnostic.Logger; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; +import java.io.*; import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; public class CSharpierProcessPipeMultipleFiles implements ICSharpierProcess, Disposable { private final boolean useUtf8; @@ -39,6 +31,12 @@ private void startProcess() { this.stdin = new OutputStreamWriter(this.process.getOutputStream(), charset); this.stdOut = new BufferedReader(new InputStreamReader(this.process.getInputStream(), charset)); + + // if we don't read the error stream, eventually too much is buffered on it and the plugin hangs + var errorGobbler = new StreamGobbler(this.process.getErrorStream()); + errorGobbler.start(); + + } catch (Exception e) { this.logger.error("error", e); } @@ -109,4 +107,22 @@ public void dispose() { this.process.destroy(); } } + + private class StreamGobbler extends Thread { + InputStream inputStream; + + private StreamGobbler(InputStream inputStream) { + this.inputStream = inputStream; + } + + @Override + public void run() { + try { + var streamReader = new InputStreamReader(this.inputStream); + var reader = new BufferedReader(streamReader); + while (reader.readLine() != null) {} + } + catch (IOException ioe) { } + } + } } diff --git a/Src/CSharpier.Rider/src/main/java/com/intellij/csharpier/ReformatWithCSharpierOnSave.java b/Src/CSharpier.Rider/src/main/java/com/intellij/csharpier/ReformatWithCSharpierOnSave.java index fb5b8975b..5453e86f1 100644 --- a/Src/CSharpier.Rider/src/main/java/com/intellij/csharpier/ReformatWithCSharpierOnSave.java +++ b/Src/CSharpier.Rider/src/main/java/com/intellij/csharpier/ReformatWithCSharpierOnSave.java @@ -1,6 +1,5 @@ package com.intellij.csharpier; -import com.intellij.application.Topics; import com.intellij.ide.actions.SaveAllAction; import com.intellij.ide.actions.SaveDocumentAction; import com.intellij.openapi.actionSystem.AnAction; @@ -15,11 +14,6 @@ public class ReformatWithCSharpierOnSave implements AnActionListener { private final Logger logger = CSharpierLogger.getInstance(); - public ReformatWithCSharpierOnSave() { - // TODO this is deprecated and should be switched to https://plugins.jetbrains.com/docs/intellij/messaging-infrastructure.html#subscribing-to-a-topic - Topics.subscribe(AnActionListener.TOPIC, null, this); - } - @Override public void beforeActionPerformed(@NotNull AnAction action, @NotNull AnActionEvent event) { if (action instanceof SaveDocumentAction) { diff --git a/Src/CSharpier.Rider/src/main/resources/META-INF/plugin.xml b/Src/CSharpier.Rider/src/main/resources/META-INF/plugin.xml index 006a93b96..2a5b7710e 100644 --- a/Src/CSharpier.Rider/src/main/resources/META-INF/plugin.xml +++ b/Src/CSharpier.Rider/src/main/resources/META-INF/plugin.xml @@ -7,7 +7,6 @@ com.intellij.modules.rider - @@ -26,4 +25,8 @@ + + +