Search code examples
ignite

PrintWriter mystery in Ignite


I am using two nodes, one that starts off the computation from the IDE (Intellij IDEA) and another that has already been started on the console (remote debugging enabled). I am debugging both from the IDE.

I am not using peerClassLoading, I have placed the jar in the libs from the console node.

There is a line of code: System.out.println(x); - which prints fine in both. But the following lines:

getPrintWriter().println(x);
getPrintWriter().flush();

work only on the node started from the IDE. The PrintWriter wraps a System.out. The console node throws IOException - 'the file handle is invalid' during flush.

Here is the screenshot of the stacktrace:

enter image description here

and here is the relevant part of the code with the console node:

enter image description here


Following suggestion, I reset the print writer and the issue was resolved. Here is the screenshot:

enter image description here


The Serialization Context

Here is the part of the code that starts up the ignite computation:

enter image description here

For the node on console JVM, ConsoleClient gets serialized and so its containing classes (commands, listeners and their print writers etc.). In the list clients, all ConsoleClient objects had their print writers as wrappers of System.out, so ideally, the marked block in the runnable should not be needed. Note that, if this marked block is removed the IDE nodes print properly, but not the console node.


Solution

  • This PrintWriter tries to delegate to FileOutputStream, so it's either not System.out underneath or System.out is replaced. Ignite never does this, so the issue is not related to it. You should check the code of getPrintWriter() method and make sure that System.out is the console writer that you're looking for.