Fixed issue with nil errors causing deadlock in controller.
Fixed issue with nil errors causing deadlock in controller.

This was a difficult one to reproduce and it basically deadlocked the
daemon. What happened was that forwarding Goroutines returned the error
from io.Copy, which is nil in the case of io.EOF. Our code was assuming
that failureCause was always non-nil. This was causing a panic when we
tried to invoke Error on it, and this unfortunately happened while we
held the state lock. This panic propagated to the defer, which also
tried to grab the already locked state lock, thus freezing the whole
program without the panic ever bubbling to the surface (the daemon froze
on shutdown while waiting for sessions to halt).

This commit fixes this problem by attempting to reconstitute the io.EOF
errors (giving a more accurate picture of problems that arise) and
adding an explicit sanity check that the error is non-nil.

Unfortunately there isn't really any structural change that we can make
to avoid this kind of thing - we're really bound by our desire to have
efficient state update tracking. If Go's mutex implementation tracked
poisoning (i.e. panics while held) then it wouldn't have been an issue,
but once the process was hung, it easy to get a full stack trace with
kill -ABRT.

havoc-io/mutagen,havoc-io/mutagen