martylamb/nailgun — pull request #52 by bgertzfield (2014-11-24 19:21:54+00:00)
Title: Explicitly close PrintStreams so they flush to the client socket

We ran into an issue in Buck where the nailgun C client would have its
socket closed unexpectedly by the server before it received the exit
command (X).

I went through NGSession with a fine-toothed comb and found its use of
PrintStream was unsafe: it used the constructor `PrintStream(OutputStream out)`
which explicitly does not flush any data unless you call `flush()` or `close()`.

This diff simply ensures we always explicitly call `PrintStream.close()` to
flush all data before closing the client socket in `NGSession`.

The vast majority of this diff is whitespace changes due to adding a
try / catch block (I assume we can't add dependencies on Java 7
try-with-resources), so add `?w=1` to the end of the github URL to
view it without whitespace changes