Closed nandorholozsnyak closed 2 years ago
Yeah. At the moment the action is blocking where it should be async + show output.
But weird it never completes though. It should.
Yeah. At the moment the action is blocking where it should be async + show output.
But weird it never completes though. It should.
Yeah I know, it is this: https://github.com/jbangdev/jbang-idea/issues/19
But this newly opened is never ending, makes the IDE fully blocked and I have to close it from the Task Manager.
@linux-china do you have an idea what could cause it?
@nandorholozsnyak I will take a look. It happened sometime, right? Sometime success and sometime fail.
Always fails. I mean, always kills the IDEA. I have to shutdown it from the Task Manager.
@nandorholozsnyak could you do me a favor? Run following code on your laptop.
///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 11
public class Hello {
public static void main(String... args) throws Exception {
String jbangCmd = "jbang.cmd";
ProcessBuilder pb = new ProcessBuilder(jbangCmd, "info", "classpath", "--fresh", "jbang-demo/hello.java");
Process process = pb.start();
process.waitFor();
}
}
If possible, could you change JAVA_HOME to jbr directory of IDEA_DIR and test again?
Hey @linux-china,
First run without setting the JAVA_HOME to jbr:
X:\linux-china-jbang
λ jbang Hello.java
[jbang] Building jar...
After setting the JAVA_HOME and PATH to the jbr.
X:\linux-china-jbang
λ set | grep JAVA_HOME
JAVA_HOME=C:\Program Files\JetBrains\IntelliJ IDEA 212.4746.2\jbr
X:\linux-china-jbang
λ which java
/c/Program Files/JetBrains/IntelliJ IDEA 212.4746.2/jbr/bin/java
X:\linux-china-jbang
λ jbang Hello.java
X:\linux-china-jbang
λ
Prompt comes back, nothing is being blocked.
@maxandersen Got. I will find a Windows laptop to test it later, thanks for your help.
Right now I'm experiencing with the script that is freezing always, and I think it only freezes with just this one specific script, I'm experimenting with the deps now, I'm assuming maybe the @pom directive kills it or the Quarkus deps, IDK yet. Here are the an example script that kills the IDEA on sync.
///usr/bin/env jbang "$0" "$@" ; exit $?
// Update the Quarkus version to what you want here or run jbang with
// `-Dquarkus.version=<version>` to override it.
//DEPS io.quarkus:quarkus-bom:${quarkus.version:2.6.0.Final}@pom
//DEPS io.quarkus:quarkus-picocli
//DEPS io.quarkus:quarkus-qute
//DEPS io.quarkus:quarkus-jackson
//DEPS commons-io:commons-io:2.11.0
//Q:CONFIG quarkus.banner.enabled=false
//Q:CONFIG quarkus.log.level=WARN
import static java.lang.System.*;
public class Hello {
public static void main(String... args) {
out.println("Hello World");
}
}
I do not really understand, if any of the Quarkus dependencies are in the list, with the BOM without version, or without the BOM and with version, IDEA freezes and that is all, without the Quarkus dependencies, only wiht the commons-io:commons-io:2.11.0 dependency the dependencies got synced.
And yes! If the jbang-demo/hello.java
file has the same dependencies then the jbang Hello.java got stuck. Interesting! I hope it will help.
@maxandersen your sync operation is to gradle or IDEA module?
It works on my mac laptop with sync to IDEA module.
And on Linux too. But on Windows there are some problem with that. :/
There are two issues here:
1) jbang plug-in runs it's jbang process executions in the main event loop blocking everything. It should not do that. Any failure Or long time processing a jbang call can do should not block the ide. No matter which OS.
2) figure out why when jbang called from IntelliJ is sometimes stuck.
The most interesting stuff is that it happens only with Quarkus dependencies... I will do some other tests and will let you know about the results.
@nandorholozsnyak what version of jbang are you running ? what does jbang version
give you ?
I have a theory that the issue is that under windows the jbang info classpath
somehow does not close the streams properly and thus java keeps waiting for the process.
I've seen that before in other cases dealing with java process launch. Why it happens only for Quarkus dependencies I'm not sure about - my guess will be that it has enough dependencies to trigger a flush() that you would not see for other cases with less dependencies.
@quintesse rings a bell?
...weird though why it freezes for you inside idea but not when running the "launch jbang" script @linux-china provided....could it be a JVM difference? like intellij runs with a different jvm than the one you use on the command line?
@nandorholozsnyak what version of jbang are you running ? what does
jbang version
give you ?
JBang version: 0.88.0
I'm able to reproduce on the command line using what @nandorholozsnyak mentioned earlier:
And yes! If the jbang-demo/hello.java file has the same dependencies then the jbang Hello.java got stuck. Interesting! I hope it will help.
Edit: tested with both 0.87.0 and 0.88.0
It must by an IO problem because adding pb.inheritIO()
to the code above fixes the hang.
I think Windows might be a little bit more strict than Linux/MacOS or has smaller buffers or something. Because in the code examples I see on the Internet I think the idea is that you first handle any IO before you do a waitFor()
. In the case of the IDEA plugin this is done the other way around: it first runs waitFor()
and then handles the IO.
It works with the pb.inheritIO()
with the script mentioned above . Would it make sense to put it into the JbangCli.kt too? Could it be marked as some fix or just a workaround?
@maxandersen I added pb.inheritIO() to JbangCli.kt, but failed to get output from process output, and I will try to fix it today. I will try https://github.com/zeroturnaround/zt-exec
The key is in what @quintesse references. We should be pumping stdin/out during run.
I have had this issue with karate test suite. Failed on windows at different times because the stdin/out was not emptied properly.
There must be a way in IntelliJ where they have mechanics to process the input/output.
And yes ztexec does this right.
@nandorholozsnyak I built a new version with zt-exec, and could you try it on your script?
@linux-china Look better, IDEA does not freeze, BUT! The jbang dependency for the module is not being created.
If yes (I have to do the Sync action a few times), then all the path is wrong.
@nandorholozsnyak my bad :( Caused by return output.split(':', ';').filter { !it.contains(".jbang") }
and it should be output.split(File.pathSeparator).filter { !it.contains(".jbang") }
I should find a Windows laptop to test. At least we fixed the process output problem on windows.
Sorry for this stupid bug, and try new build.
I'm here to test ;)
@linux-china so much better!
I cleared my Quarkus dependencies from my laptop, took a few seconds to download them, but it is working. Any plan for the UI blocking? Could it done in background somehow?
@nandorholozsnyak Introduce ProgressManager and Task.Backgroundable to sync dependencies asynchronously. If all good after your trial, and I will release new version.
@linux-china works like charm. Superb enhancement! Good job.
So when I try to sync some JBang script's dependencies in IDEA with the
Sync JBang DEPS to Module
the whole IDE freezes and I have to force shutdown it. It happens only on Windows for me.JBang version:
0.88.0
JBang IDEA plugin version:0.15.0
IDEA version:IntelliJ IDEA 2021.3.2 Build #IU-213.6777.52, built on January 28, 2022
but if I remember well it happened on earlier IDEA version as well.What I saw in the threadDump is that this command line stucks, and waits forever: https://github.com/jbangdev/jbang-idea/blob/main/src/main/kotlin/dev/jbang/idea/JBangCli.kt#L30
If I run the following command in the command line
jbang.cmd info classpath --fresh src/script.java
it succeeds.Here is the threadDump log for it: