Fix EGit deadlock listing branches of SSH remote

When listing branches, EGit only reads the advertisement and
then disconnects.  When it closes down the pack channel the remote
side is waiting for the client to send our list of commands, or a
flush-pkt to let it know there is nothing to do.

However if an error thread is open watching the SSH stderr stream,
we ask for it to finish before we send the flush-pkt.  Unfortunately
the thread won't terminate until the main output stream closes,
which is waiting for the flush-pkt.  A classic network deadlock.

If the output stream needs a flush-pkt we send it before we wait
for the error stream to close.  If the flush-pkt is rejected, we
close down the output stream early, assuming that the remote side
is broken and we will get error information soon.

Change-Id: I8d078a339077756220c113f49d206b1bf295d434
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2 files changed