-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ctrl-C + Return crashes jline #590
Comments
After modifying the 'while(true)' loop so it instead looked like this 'while(exceptionCounter < 1)' plus incrementing the counter in the different catch clauses plus printing the stack trace in these I get the following result
How to recover from this? |
Might be git bash/Mintty problem. There are problems reported on the latest git bash versions, see #560. I'm using git bash on Windows 10 and I'm not able to reproduce your problem using my app.
|
The problem has been reproduced in git bash version 2.29.2.windows.2 and mintty version 3.4.2. Pressing ctrl-c new signal handlers should be created. When you press ctrl-c INT signal handler is called, after enter
If after ctrl-c you press an other key different than return the
In linux where we do not have the problem after ctrl-c new signal handlers are registered:
|
Mintty Ctrl-C handling mintty/mintty#684 As a work around you can disable entirely the interrupt function of Ctrl-C entering the command |
I have encountered the same issue with jline 3.20.0. It is caused by a bug in the LineReaderImpl class. } catch (IOError e) {
if (e.getCause() instanceof InterruptedIOException) {
throw new UserInterruptException(buf.toString());
} else {
throw e;
}
}
finally {
try {
lock.lock();
this.reading = false;
cleanup();
if (originalAttributes != null) {
terminal.setAttributes(originalAttributes);
}
if (previousIntrHandler != null) {
terminal.handle(Signal.INT, previousIntrHandler);
}
if (previousWinchHandler != null) {
terminal.handle(Signal.WINCH, previousWinchHandler);
}
if (previousContHandler != null) {
terminal.handle(Signal.CONT, previousContHandler);
}
} finally {
lock.unlock();
}
startedReading.set(false);
} Notice two things: first the finally block tries to set the terminal's original attributes. On certain system terminals this involves actually starting a new process and reading its output. Since our thread has been interrupted and the interrupt flag has not been reset yet, the internal call to Process.waitFor() immediately throws an exception, which is not handled and propagates to the user code. The second thing to notice is that at the very end of the finally block, an AtomicBoolean value is set to false. This is important, since this value controls how the LineReader behaves - if the value is true, you cannot call readLine() again until it has been reset. |
Any update on this? I'm still getting the same problem on the latest Git snapshot 2.36.0.rc2.windows.1 with bash 4.4.23 and couldn't find much related to this in git-for-windows/git. At the moment I'm unable to test the latest jline directly in Java, but the issue is present in Paper which uses jline 3.21.0. |
I was playing around with the picocli.shell.jline3.example.Example application found here
https://github.com/remkop/picocli/blob/master/picocli-shell-jline3/README.md
and I noticed that if I press Ctrl-C followed by Return I got the following crash
java.io.IOError: java.io.InterruptedIOException: Command interrupted
at org.jline.terminal.impl.AbstractPosixTerminal.setAttributes(AbstractPosixTerminal.java:54)
at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:715)
at picocli.shell.jline3.example.Example.main(Example.java:190)
Caused by: java.io.InterruptedIOException: Command interrupted
at org.jline.utils.ExecHelper.exec(ExecHelper.java:46)
at org.jline.terminal.impl.ExecPty.doGetConfig(ExecPty.java:175)
at org.jline.terminal.impl.ExecPty.getAttr(ExecPty.java:87)
at org.jline.terminal.impl.ExecPty.doSetAttr(ExecPty.java:93)
at org.jline.terminal.impl.AbstractPty.setAttr(AbstractPty.java:29)
at org.jline.terminal.impl.AbstractPosixTerminal.setAttributes(AbstractPosixTerminal.java:52)
... 2 more
Caused by: java.lang.InterruptedException
at java.base/java.lang.ProcessImpl.waitFor(ProcessImpl.java:552)
at org.jline.utils.ExecHelper.waitAndCapture(ExecHelper.java:66)
at org.jline.utils.ExecHelper.exec(ExecHelper.java:36)
... 7 more
Furthermore, when editing a line I press Ctrl-C and then Down-arrow/Ctrl-n a UserInterruptedException is thrown, but only the first time!
And then I modified the while-loop that starts on line 187 so it looked like this
This resulted in a never-ending loop that printed lots of "Exception!" followed by lots of "Caught exception: java.lang.IllegalStateException" followed by "Exception!" followed by in another color (red?)... And the Mintty terminal ended up in a strange state where it no longer echoes what I type...
I dont know if it matters or not, but I'm currently using git bash running in the default Mintty terminal on Windows 10.
Regardless it would of course be great if this bug could be fixed, and I also think that it would be nice if pressing Ctrl-C would abort the editing of the current line (just like it does in for instance Bash). Is this possible to do?
The text was updated successfully, but these errors were encountered: