ZOOKEEPER-5021: Exit from zkCli when interrupt (Ctrl-C) or EOF (Ctrl-D) is pressed#2357
ZOOKEEPER-5021: Exit from zkCli when interrupt (Ctrl-C) or EOF (Ctrl-D) is pressed#2357PDavid wants to merge 1 commit intoapache:masterfrom
Conversation
…D) is pressed Problem Closing the input stream for a terminal by pressing "Ctrl-D" should automatically exit the interactive shell, but the bin/zkCli.sh does not exit, but does disable JLine support, leaving you at a prompt-less terminal. Pressing "Ctrl-D" a second time exited correctly, and so did entering "quit" (without JLine support enabled). Cause After the JLine 3.x upgrade, pressing Ctrl-C or Ctrl-D results in InvocationTargetException which we caught and set the jlinemissing flag to true to fall back to the promptless shell. Fix When the cause of the InvocationTargetException is either EndOfFileException or UserInterruptException, we should not set the jlinemissing flag to true to not fall back to the promptless shell.
TestingBuilt the project with After this fix pressing a Ctrl-D (or Ctrl-C) one time should exit the ZK shell (and should not print "JLine support is disabled" and drop you into prompltess shell where you have to Ctrl-D / Ctrl-C again). |
|
Many thanks for your reviews. 👍 Are you happy merging this fix or is it better to wait for more reviews on this? |
| endOfFileExceptionC = Class.forName("org.jline.reader.EndOfFileException"); | ||
| userInterruptExceptionC = Class.forName("org.jline.reader.UserInterruptException"); | ||
|
|
||
| System.out.println("JLine support is enabled"); |
There was a problem hiding this comment.
How about setting jlinemissing to true initially and to false here ?
There was a problem hiding this comment.
Ah, many thanks! 👍
This makes perfect sense and this is so much simpler and easier than I implemented here. 🤦♂️ 😄
I tried this out and works nicely. Please check it here: #2369
|
Closing this in favor of #2369 |
For what it's worth, you don't need to create a new PR if changing the implementation in response to code review feedback. You can just push to the branch you made the PR from, and it automatically updates the PR with the changes. |
Thanks, true, I know. 👍 |
Problem
Closing the input stream for a terminal by pressing "Ctrl-D" should automatically exit the interactive shell, but the bin/zkCli.sh does not exit, but does disable JLine support, leaving you at a prompt-less terminal. Pressing "Ctrl-D" a second time exited correctly, and so did entering "quit" (without JLine support enabled).
Cause
After the JLine 3.x upgrade, pressing Ctrl-C or Ctrl-D results in
InvocationTargetExceptionwhich we caught and set thejlinemissingflag to true to fall back to the promptless shell.Fix
When the cause of the
InvocationTargetExceptionis eitherEndOfFileExceptionorUserInterruptException, we should not set thejlinemissingflag to true to not fall back to the promptless shell.This way the behavior aligns with what we had before the JLine 3.x upgrade.