proto: Fix both-ends-cancel case.
authorRichard W.M. Jones <rjones@redhat.com>
Fri, 18 Mar 2011 18:27:21 +0000 (18:27 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Mon, 21 Mar 2011 11:36:13 +0000 (11:36 +0000)
commit56bbd763134fa40c3f52799660fed83c325de36c
treeccf0e8c40ba15aa0fe47bd09dc33f6601a4c4912
parent821083b1c46005cfeebf384e81be812f6b0cc74b
proto: Fix both-ends-cancel case.

In the case where both ends cancel at the same time (eg. both ends
realize there are errors before or during the transfer), previously we
skipped sending back an error from the daemon, on the spurious basis
that the library would not need it (the library is cancelling because
of its own error).

However this is wrong: we should always send back an error message
from the daemon in order to preserve synchronization of the protocol.

A simple test case is:

  $ guestfish -N fs -m /dev/sda1 upload nosuchfile /
  libguestfs: error: open: nosuchfile: No such file or directory
  libguestfs: error: unexpected procedure number (66/282)

(Notice two things: there are errors at both ends, and the
loss of synchronization).

After applying this commit, the loss of synchronization does not occur
and we just see the library error:

  $ guestfish -N fs -m /dev/sda1 upload nosuchfile /
  libguestfs: error: open: nosuchfile: No such file or directory

The choice of displaying the library or the daemon error is fairly
arbitrary in this case -- it would be valid to display either or even
to combine them into one error.  Displaying the library error only
makes the code considerably simpler.

This commit also (re-)enables a test for this case.

Cherry picked and rebased from
commit f4d996fd26762053d68f46de5790aae893f03d38.
daemon/base64.c
daemon/debug.c
daemon/tar.c
daemon/upload.c
generator/generator_c.ml
generator/generator_daemon.ml
regressions/Makefile.am
src/guestfs-internal.h
src/proto.c