Closed FerusGrim closed 7 years ago
Just for further clarification, the error is more specifically occurring at where TCA#append(LogEvent)
calls to LineReaderImpl#callWidget(String)
, at this line:
if (!reading) {
throw new IllegalStateException();
}
So... for whatever reason, the implementation of LineReader is declaring that it's NOT reading?
In case this an error on my part, somehow, here is my related code:
https://gist.github.com/FerusGrim/cc20a87f7529012ca154539de1a1047a
You need to remove the reader from TerminalConsoleAppender before writing to the logger again. Normally, this is handled by the finally block, however the problem here is the way you shutdown the application, directly in the console thread. It should work if you add TerminalConsoleAppender.setReader(null)
directly before the logger call in the catch block of UserInterruptException
: https://gist.github.com/FerusGrim/cc20a87f7529012ca154539de1a1047a#file-consolelistener-java-L47
Edit: Same applies for your call above in https://gist.github.com/FerusGrim/cc20a87f7529012ca154539de1a1047a#file-consolelistener-java-L42. I recommend that you never execute commands/the shutdown on the console thread but just set an indication for the main/another thread that a command was executed (e.g. a queue). This will make sure that the console is always available for command input without delays.
This should fix the error in most cases. I'm aware that there are some race conditions in which it is possible that the reader is still registered in the illegal state when a new message is sent but I haven't found a simple solution for that yet.
Yup! The above definitely fixes it.
For future reference: (TL;DR of @Minecrell's post)
TerminalConsoleAppender.setReader(null)
@FerusGrim Thanks for the summary! :)
Note: With TCA 1.1.0 it is no longer necessary to temporarily call TerminalConsoleAppender.setReader(null)
when running the command on the same thread. You should only call it if you no longer need the LineReader
so it can be destroyed by GC.
During normal logging, no issues seem to appear.
However, when submitting a message, this stacktrace is always thrown:
The stacktrace seems to be referring to:
When that line is commented out, the same error occurs but then points to:
And then:
It may be more apt to say that any calls to
LineReader#callWidget(String)
are resulting in an IllegalStateException.It's worth noting, however, that the command/input DOES get processed correctly.