proto: Don't drop outgoing message when daemon cancels (RHBZ#576879).
authorRichard Jones <rjones@redhat.com>
Fri, 18 Mar 2011 16:18:37 +0000 (16:18 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Mon, 21 Mar 2011 11:33:13 +0000 (11:33 +0000)
commit1fba33e4ba3c0286b65167781fd48bb8b525a102
treeb7b3b528ad4d1e48feb48bf5e40bcb458ff518f8
parent1f94d8dcc74c82f9ba57d191b3315c4eb8236d43
proto: Don't drop outgoing message when daemon cancels (RHBZ#576879).

This is a (potential) fix for the long standing protocol bug
which causes loss of synchronization when a FileIn action
fails very early on the daemon side.  The canonical example
would be the 'upload' action failing immediately if no filesystem
is mounted.

What's supposed to happen is this:

  (1) library sends
  request message              (2) daemon processes request
  first chunk of data          and sees that it will fail,
                               sends cancellation
                               (3) discards chunks of data
  (4) library sees daemon
  cancellation and stops
  sending chunks

It was going wrong in step (1), in guestfs___send_to_daemon.
In some (timing related) circumstances, send_to_daemon could
receive the cancellation before sending the first chunk, at
which point it would exit, *discarding the first chunk*.
This causes the daemon to fail in step (3) since it reads the
next request as if it was a chunk, thus losing synchronization.
(The protocol specifies that you always have to send at least
one chunk if there is a FileIn or FileOut parameter).

The patch changes guestfs___send_to_daemon so that if it detects
cancellation, it sends the remaining data in its output buffer
instead of discarding it.  (This also fixes another edge case
to do with sending partial data although I don't think we
ever saw that in practice).
(cherry picked from commit c7368ce167d6dbfd3e69ba208301c5af3f17a8a1)
src/proto.c