[PATCH] chg: handle EOF reading data block

Jun Wu quark at fb.com
Tue Jul 19 09:07:23 EDT 2016

Excerpts from Yuya Nishihara's message of 2016-07-19 21:42:12 +0900:
> I'm curious when blocking recv() may return 0 other than EOF and zero-size
> request. I suspect that the original condition "rsize < 0" was totally wrong.

Manpage says it could return 0 for zero-length datagrams:

   Datagram sockets in various domains (e.g., the UNIX and Internet domains)
   permit zero-length datagrams.  When such a datagram is received, the
   return value is 0.

This is ugly but I don't think we have too many choices.

I'm more concerned about the root cause. It seems like nested channedoutput
writing. We probably want to make use of stdio locking by merging the two
write calls:

  diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
  --- a/mercurial/commandserver.py
  +++ b/mercurial/commandserver.py
  @@ -54,8 +54,8 @@ class channeledoutput(object):
       def write(self, data):
           if not data:
  -        self.out.write(struct.pack('>cI', self.channel, len(data)))
  -        self.out.write(data)
  +        buf = struct.pack('>cI', self.channel, len(data)) + data
  +        self.out.write(buf)

More information about the Mercurial-devel mailing list