<br><font size=2 face="sans-serif">I apologise for top posting. The email
client I am forced to use forces me.</font>
<br>
<br><font size=2 face="sans-serif">What Jamie says below seems to imply
to me that the rsync protocol needs to be extended to include clean shutdown.
AFAIK WinSock still behaves the same way it always did so it will not be
able to do the same kind of cleanup that you can in Unix. But Jamie seems
to be saying that on unix a shutdown would cause a RST signal anyway. So
I am really not sure where this leaves me.</font>
<br>
<br><font size=2 face="sans-serif">Surely other people have been seeing
this problem when doing an rsync to hundreds of machines at the same time.
Out of around 200 machines I got these errors from over a dozen today.
That's more than usual but it's all random when it comes down to it. I
wonder who else is rsyncing on this scale.</font>
<br>
<br><font size=2 face="sans-serif">Regards,<br>
<br>
Andrew Marlow<br>
</font>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=33%><font size=4 face="helv"><b>Internet &nbsp;</b></font>
<br><font size=1 face="sans-serif"><b>jamie@shareable.org</b></font>
<p><font size=1 face="sans-serif">02/06/2010 13:55</font>
<td width=66%>
<table width=100%>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td><font size=1 face="sans-serif">Andrew MARLOW</font>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td><font size=1 face="sans-serif">rsync@lists.samba.org</font>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td><font size=1 face="sans-serif">Re: rsync 3.0.7 network errors on MS-Windows</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><font size=2><tt>andrew.marlow@uk.bnpparibas.com wrote:<br>
&gt; <br>
&gt; &nbsp; &nbsp;I am experiencing intermittent network failures on rsync
3.0.7 built<br>
&gt; &nbsp; &nbsp;using cygwin for Windows-XP (SP2). I am using GCC v4.4.2
and the<br>
&gt; &nbsp; &nbsp;latext version of cygwin.<br>
&gt; &nbsp; &nbsp;The rsync error long indicates things like:<br>
&gt; &nbsp; &nbsp;rsync: writefd_unbuffered failed to write 4092 bytes
to socket<br>
&gt; &nbsp; &nbsp;[generator]:<br>
&gt; &nbsp; &nbsp;Connection reset by peer (104)rsync: read error: Connection
reset by<br>
&gt; &nbsp; &nbsp;peer (104)<br>
&gt; &nbsp; &nbsp;rsync error: error in rsync protocol data stream (code
12) at<br>
&gt; &nbsp; &nbsp;io.c(1530) [generator=3.0.7]<br>
&gt; &nbsp; &nbsp;rsync error: error in rsync protocol data stream (code
12) at<br>
&gt; &nbsp; &nbsp;io.c(760) [receiver=3.0.7]<br>
&gt; &nbsp; &nbsp;Googling I see that these problems were put down to the
way socket are<br>
&gt; &nbsp; &nbsp;cleaned up in Windows and a fix put in place in cleanup.c,
in<br>
&gt; &nbsp; &nbsp;close_all(). But the fix is surrounded by conditional
compilation:-<br>
&gt; &nbsp; &nbsp;#ifdef SHUTDOWN_ALL_SOCKETS<br>
&gt; &nbsp; &nbsp; &nbsp; :<br>
&gt; &nbsp; &nbsp; &nbsp; :<br>
&gt; &nbsp; &nbsp;#endif<br>
&gt; &nbsp; &nbsp;Can someone please explain why that is? Shouldn't the
fix just be<br>
&gt; &nbsp; &nbsp;there always, and regardless of which operating system?<br>
<br>
It's not needed on most operating systems - as the comment there implies.<br>
<br>
According to the notes copied below, SO_LINGER is off by default on<br>
unix sockets, and this means close() will gracefully send the<br>
remaining data in the background, rather than TCP RST. &nbsp;You can assume<br>
that program exit has the same effect as close().<br>
<br>
If SO_LINGER is turned on with a zero timeout, the notes below say TCP<br>
RST is sent on close, which is much like what the comment for<br>
SHUTDOWN_ALL_SOCKETS says is happening on Windows without SO_LINGER.<br>
<br>
Presumably Windows sockets - or at least some version of them (there<br>
are several versions of Winsock) - behaves differently from unix<br>
sockets in this area. &nbsp;It wouldn't be surprising, as historically<br>
Winsock ran inside the process not the kernel, so an exiting process<br>
couldn't implement the unix graceful close behaviour, and maybe they<br>
kept that behaviour the same in later versions.<br>
<br>
That said, I still don't see why SHUTDOWN_ALL_SOCKETS would fix it.<br>
Calling shutdown(fd,2) closes it in both directions, and at least with<br>
usual unix sockets, that would trigger TCP RST anyway if the other end<br>
sends any data after the shutdown.<br>
<br>
Which it seems to be doing: &quot;writefd_unbuffered failed to write 4092<br>
bytes to socket&quot; implies the other end has closed or shutdown(fd,1)
or<br>
shutdown(fd,2), and then data is sent to it which can't be accepted so<br>
the other end sent back TCP RST anyway.<br>
<br>
If rsync is doing that in normal operation, that ought to be a problem<br>
on unix just as much as Windows - and SHUTDOWN_ALL_SOCKETS ought to be<br>
insufficient to prevent the reset.<br>
<br>
Which suggests to me that &quot;writefd_unbuffered failed to write 4092<br>
bytes to socket&quot; is a symptom of a different problem.<br>
<br>
Here are the notes I referred to above.<br>
These are the notes which explain SO_LINGER's behaviour:<br>
<br>
 &nbsp; Unix Socket FAQ<br>
 &nbsp; http://www.developerweb.net/forum/archive/index.php/t-2982.html<br>
<br>
 &nbsp; 4.6 - What exactly does SO_LINGER do?<br>
<br>
 &nbsp; Contributed by Cyrus Patel<br>
<br>
 &nbsp; SO_LINGER affects the behaviour of the close() operation as described<br>
 &nbsp; below. No socket operation other than close() is affected by SO_LINGER.<br>
<br>
 &nbsp; The following description of the effect of SO_LINGER has been culled<br>
 &nbsp; from the setsockopt() and close() man pages for several systems,
but may<br>
 &nbsp; still not be applicable to your system. The range of differences
in<br>
 &nbsp; implementation ranges from not supporting SO_LINGER at all; or
only<br>
 &nbsp; supporting it partially; or having to deal with the &quot;peculiarities&quot;
in a<br>
 &nbsp; particular implementation. (see portability notes at end).<br>
<br>
 &nbsp; Moreover, the purpose of SO_LINGER is very, very specific and only
a<br>
 &nbsp; tiny minority of socket applications actually need it. Unless you
are<br>
 &nbsp; extremely familiar with the intricacies of TCP and the BSD socket
API,<br>
 &nbsp; you could very easily end up using SO_LINGER in a way for which
it was<br>
 &nbsp; not designed.<br>
<br>
<br>
 &nbsp; The effect of an setsockopt(..., SO_LINGER,...) depends on what
the<br>
 &nbsp; values in the linger structure (the third parameter passed to<br>
 &nbsp; setsockopt()) are:<br>
<br>
 &nbsp; Case 1: linger-&gt;l_onoff is zero (linger-&gt;l_linger has no
meaning):<br>
 &nbsp; This is the default.<br>
<br>
 &nbsp; On close(), the underlying stack attempts to gracefully shutdown
the<br>
 &nbsp; connection after ensuring all unsent data is sent. In the case
of<br>
 &nbsp; connection-oriented protocols such as TCP, the stack also ensures
that<br>
 &nbsp; sent data is acknowledged by the peer. The stack will perform the<br>
 &nbsp; above-mentioned graceful shutdown in the background (after the
call to<br>
 &nbsp; close() returns), regardless of whether the socket is blocking
or<br>
 &nbsp; non-blocking.<br>
<br>
 &nbsp; Case 2: linger-&gt;l_onoff is non-zero and linger-&gt;l_linger
is zero:<br>
<br>
 &nbsp; A close() returns immediately. The underlying stack discards any
unsent<br>
 &nbsp; data, and, in the case of connection-oriented protocols such as
TCP,<br>
 &nbsp; sends a RST (reset) to the peer (this is termed a hard or abortive<br>
 &nbsp; close). All subsequent attempts by the peer's application to<br>
 &nbsp; read()/recv() data will result in an ECONNRESET.<br>
<br>
 &nbsp; Case 3: linger-&gt;l_onoff is non-zero and linger-&gt;l_linger
is non-zero:<br>
<br>
 &nbsp; A close() will either block (if a blocking socket) or fail with<br>
 &nbsp; EWOULDBLOCK (if non-blocking) until a graceful shutdown completes
or the<br>
 &nbsp; time specified in linger-&gt;l_linger elapses (time-out). Upon
time-out the<br>
 &nbsp; stack behaves as in case 2 above.<br>
<br>
 &nbsp; ---------------------------------------------------------------<br>
<br>
 &nbsp; Portability note 1: Some implementations of the BSD socket API
do not<br>
 &nbsp; implement SO_LINGER at all. On such systems, applying SO_LINGER
either<br>
 &nbsp; fails with EINVAL or is (silently) ignored. Having SO_LINGER defined
in<br>
 &nbsp; the headers is no guarantee that SO_LINGER is actually implemented.<br>
<br>
 &nbsp; Portability note 2: Since the BSD documentation on SO_LINGER is
sparse<br>
 &nbsp; and inadequate, it is not surprising to find the various implementations<br>
 &nbsp; interpreting the effect of SO_LINGER differently. For instance,
the<br>
 &nbsp; effect of SO_LINGER on non-blocking sockets is not mentioned at
all in<br>
 &nbsp; BSD documentation, and is consequently treated differently on different<br>
 &nbsp; platforms. Taking case 3 for example: Some implementations behave
as<br>
 &nbsp; described above. With others, a non-blocking socket close() succeed<br>
 &nbsp; immediately leaving the rest to a background process. Others ignore<br>
 &nbsp; non-blocking'ness and behave as if the socket were blocking. Yet
others<br>
 &nbsp; behave as if SO_LINGER wasn't in effect [as if the case 1, the
default,<br>
 &nbsp; was in effect], or ignore linger-&gt;l_linger [case 3 is treated
as case<br>
 &nbsp; 2]. Given the lack of adequate documentation, such differences
are not<br>
 &nbsp; (by themselves) indicative of an &quot;incomplete&quot; or &quot;broken&quot;<br>
 &nbsp; implementation. They are simply different, not incorrect.<br>
<br>
 &nbsp; Portability note 3: Some implementations of the BSD socket API
do not<br>
 &nbsp; implement SO_LINGER completely. On such systems, the value of<br>
 &nbsp; linger-&gt;l_linger is ignored (always treated as if it were zero).<br>
<br>
 &nbsp; Technical/Developer note: SO_LINGER does (should) not affect a
stack's<br>
 &nbsp; implementation of TIME_WAIT. In any event, SO_LINGER is not the
way to<br>
 &nbsp; get around TIME_WAIT. If an application expects to open and close
many<br>
 &nbsp; TCP sockets in quick succession, it should be written to use only
a<br>
 &nbsp; fixed number and/or range of ports, and apply SO_REUSEPORT to sockets<br>
 &nbsp; that use those ports.<br>
<br>
 &nbsp; Related note: Many BSD sockets implementations also support a<br>
 &nbsp; SO_DONTLINGER socket option. This socket option has the exact opposite<br>
 &nbsp; meaning of SO_LINGER, and the two are treated (after inverting
the value<br>
 &nbsp; of linger-&gt;l_onoff) as equivalent. In other words, SO_LINGER
with a zero<br>
 &nbsp; linger-&gt;l_onoff is the same as SO_DONTLINGER with a non-zero<br>
 &nbsp; linger-&gt;l_onoff, and vice versa.<br>
<br>
-- Jamie<br>
</tt></font>
<br><pre>
___________________________________________________________
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is prohibited.

Please refer to http://www.bnpparibas.co.uk/en/information/legal_information.asp?Code=ECAS-845C5H  for additional disclosures.
</pre>